diff --git a/Makefile b/Makefile index 9993e094..bf79e6b3 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,9 @@ build-release: tidy run: tidy @go run -tags embed_swagger main.go run --dev +run-race: tidy + @go run -race -tags embed_swagger main.go run --dev + run-tracing: tidy @go run -tags embed_swagger main.go run --tracing --dev diff --git a/network/client.go b/network/client.go index 82dfcc1a..d6b6f403 100644 --- a/network/client.go +++ b/network/client.go @@ -181,29 +181,23 @@ func (c *Client) Receive() (int, []byte, *gerr.GatewayDError) { var received int buffer := bytes.NewBuffer(nil) // Read the data in chunks. - for { - chunk := make([]byte, c.ReceiveChunkSize) - read, err := c.Conn.Read(chunk) - switch { - case read > 0 && err != nil: - received += read - buffer.Write(chunk[:read]) - c.logger.Error().Err(err).Msg("Couldn't receive data from the server") - metrics.BytesReceivedFromServer.Observe(float64(received)) - span.RecordError(err) - return received, buffer.Bytes(), gerr.ErrClientReceiveFailed.Wrap(err) - case err != nil: - c.logger.Error().Err(err).Msg("Couldn't receive data from the server") - metrics.BytesReceivedFromServer.Observe(float64(received)) - span.RecordError(err) - return received, buffer.Bytes(), gerr.ErrClientReceiveFailed.Wrap(err) - default: + select { //nolint:gosimple + case <-time.After(time.Millisecond): + for { + chunk := make([]byte, c.ReceiveChunkSize) + read, err := c.Conn.Read(chunk) + if err != nil { + c.logger.Error().Err(err).Msg("Couldn't receive data from the server") + span.RecordError(err) + metrics.BytesReceivedFromServer.Observe(float64(received)) + return received, buffer.Bytes(), gerr.ErrClientReceiveFailed.Wrap(err) + } received += read buffer.Write(chunk[:read]) - } - if read == 0 || read < c.ReceiveChunkSize { - break + if read == 0 || read < c.ReceiveChunkSize { + break + } } } metrics.BytesReceivedFromServer.Observe(float64(received))