Skip to content

fix: keep response body readable during Backoff#291

Open
happysnaker wants to merge 1 commit into
hashicorp:mainfrom
happysnaker:fix-backoff-response-body
Open

fix: keep response body readable during Backoff#291
happysnaker wants to merge 1 commit into
hashicorp:mainfrom
happysnaker:fix-backoff-response-body

Conversation

@happysnaker

Copy link
Copy Markdown

Summary

When Client.Do decides to retry, it currently drains and closes resp.Body before invoking Backoff. That makes Backoff callbacks unable to inspect retry hints carried in the response body and reproduces the http2: response body closed problem described in #215.

This change moves the body drain/close step to after Backoff returns, so custom backoff policies can still read the response body during the callback while the connection reuse behavior stays unchanged for the next attempt.

It also documents that resp.Body remains readable while Backoff runs and is drained/closed immediately afterwards when a retry will proceed.

Closes #215.

What changed

  • call Backoff(...) before drainBody(resp.Body) on retry paths
  • document the response-body lifetime around Backoff
  • add focused regression coverage proving Backoff can read the retry response body

Notes

  • no exported API changes
  • if a Backoff callback fully consumes the body, the later drain becomes a no-op and still closes it as before

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot read the response body inside the Backoff function (I think)

1 participant