Skip to content

Commit

Permalink
Sarthak | Corrects defer inside ResponseReader
Browse files Browse the repository at this point in the history
  • Loading branch information
SarthakMakhija committed Jan 19, 2024
1 parent 664acd1 commit 15720a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions report/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"
)

// Reports represents the report that is displayed to the user after the load is completed.
// Report reports represents the report that is displayed to the user after the load is completed.
// Report contains LoadMetrics and ResponseMetrics.
// LoadMetrics defines fields that are relevant to the generated load, whereas
// ResponseMetrics defines the fields that are relevant to the response read by blast.
Expand Down Expand Up @@ -120,7 +120,7 @@ func (reporter *Reporter) PrintReport(writer io.Writer) {
if reporter.responseMetricsDoneChannel != nil {
<-reporter.responseMetricsDoneChannel
}
print(writer, reporter.report)
_ = print(writer, reporter.report)
}

// TotalLoadReportedTillNow returns the total load that has reporter so far.
Expand Down
22 changes: 11 additions & 11 deletions report/response_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,26 @@ func NewResponseReader(
}

// StartReading runs a goroutine that reads from the provided net.Conn.
// It keepts on reading from the connection until either of the two happen:
// 1) Reading from the connnection returns an io.EOF error
// It keeps on reading from the connection until either of the two happen:
// 1) Reading from the connection returns an io.EOF error
// 2) ResponseReader gets stopped
// ResponseReader implements one goroutine for each new connection created by the workers.WorkerGroup.
func (responseReader *ResponseReader) StartReading(connection net.Conn) {
go func(connection net.Conn) {
for {
defer func() {
_ = connection.Close()
if err := recover(); err != nil {
fmt.Fprintf(os.Stderr, "[ResponseReader] %v\n", err.(error).Error())
}
}()
defer func() {
_ = connection.Close()
if err := recover(); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "[ResponseReader] %v\n", err.(error).Error())
}
}()

for {
select {
case <-responseReader.stopChannel:
return
default:
if responseReader.readDeadline != time.Duration(0) {
connection.SetReadDeadline(time.Now().Add(responseReader.readDeadline))
_ = connection.SetReadDeadline(time.Now().Add(responseReader.readDeadline))
}
buffer := make([]byte, responseReader.responseSizeBytes)
n, err := connection.Read(buffer)
Expand All @@ -100,7 +100,7 @@ func (responseReader *ResponseReader) StartReading(connection net.Conn) {
}(connection)
}

// Closes closes the stopChannel which stops all the goroutines.
// Close closes the stopChannel which stops all the goroutines.
func (responseReader *ResponseReader) Close() {
close(responseReader.stopChannel)
}
Expand Down

0 comments on commit 15720a9

Please sign in to comment.