From 9c7a5054da10b6b9da8acabdc0f4f9b19fe5f847 Mon Sep 17 00:00:00 2001 From: John Beisley Date: Sun, 8 Jun 2014 09:19:48 +0100 Subject: [PATCH] Minor corrections to error handling logic in httpu. --- httpu/httpu.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/httpu/httpu.go b/httpu/httpu.go index 1b34c25..862c3de 100644 --- a/httpu/httpu.go +++ b/httpu/httpu.go @@ -91,13 +91,17 @@ func (httpu *HTTPUClient) Do(req *http.Request, timeout time.Duration, numSends // 2048 bytes should be sufficient for most networks. n, _, err := httpu.conn.ReadFrom(responseBytes) if err != nil { - if err, ok := err.(net.Error); ok && err.Timeout() { - break + if err, ok := err.(net.Error); ok { + if err.Timeout() { + break + } + if err.Temporary() { + // Sleep in case this is a persistent error to avoid pegging CPU until deadline. + time.Sleep(10 * time.Millisecond) + continue + } } - log.Print("httpu: error while receiving response: %v", err) - // Sleep in case this is a persistent error to avoid pegging CPU until deadline. - time.Sleep(10 * time.Millisecond) - continue + return nil, err } // Parse response.