Skip to content

Commit

Permalink
Close the response body on 503
Browse files Browse the repository at this point in the history
This fixes the EOF error once and for all. It was my fault all along :(
  • Loading branch information
Evan Shaw committed Jul 12, 2012
1 parent 7845d9c commit e911c16
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions ironmq.go
Expand Up @@ -76,23 +76,17 @@ func (c *Client) req(method, endpoint string, body []byte, data interface{}) err

const maxRetries = 5
tries := uint(0)
eofCount := 0
var resp *http.Response
for tries < maxRetries {
resp, err = http.DefaultClient.Do(req)
if err != nil {
if err == io.EOF && eofCount < 3 {
golog.Debugf("Retrying because of EOF %v\nPayload: %s\n", eofCount, body)
eofCount++
req.Body = ioutil.NopCloser(bytes.NewBuffer(body))
continue
}
return err
}
// ELB sometimes returns this when load is increasing; we retry
// with exponential backoff
if resp.StatusCode == http.StatusServiceUnavailable {
golog.Debugf("Retrying because of 503 %v\nPayload: %s\n", tries, body)
resp.Body.Close()
tries++
// random delay between 0 and (4^tries*100) milliseconds
pow := int64(1) << (2 * tries) * 100
Expand Down

0 comments on commit e911c16

Please sign in to comment.