Minor corrections to error handling logic in httpu.

This commit is contained in:
John Beisley 2014-06-08 09:19:48 +01:00
parent 5cd41e8371
commit 9c7a5054da

View File

@ -91,14 +91,18 @@ 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() {
if err, ok := err.(net.Error); ok {
if err.Timeout() {
break
}
log.Print("httpu: error while receiving response: %v", err)
if err.Temporary() {
// 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.
response, err := http.ReadResponse(bufio.NewReader(bytes.NewBuffer(responseBytes[:n])), req)