Permalink
Browse files

Close the response body on 503

This fixes the EOF error once and for all. It was my fault all along :(
  • Loading branch information...
1 parent 7845d9c commit e911c16faa95387aa2c1ff707c1fc97466f06160 Evan Shaw committed Jul 12, 2012
Showing with 1 addition and 7 deletions.
  1. +1 −7 ironmq.go
View
@@ -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

0 comments on commit e911c16

Please sign in to comment.