Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix POST retries #45

Merged
merged 5 commits into from
Feb 9, 2022
Merged

Fix POST retries #45

merged 5 commits into from
Feb 9, 2022

Conversation

lvanoort
Copy link
Contributor

@lvanoort lvanoort commented Feb 8, 2022

PR fixes a couple of bugs that we discovered when investigating a situation where a failed POST request was causing a job to time out:

  1. One-line fix for a Context-cancellation issue that can cause indefinite hangs when the Context expires during a backoff wait period (a bug I introduced in Listen for context cancellation during backoff period #44 😬 )

  2. Larger fix around request body handling. The general gist of it is that currently when pester retries requests with request bodies, it will either return an error complaining about ContentLength=<some number> with Body length 0 or send the destination server a request with an empty body, depending on the type of io.Reader used and how you made the request. If you checkout c1c03d2 the added tests will demonstrate this behaviour. This issue badly exacerbates the first one since it means that any request with a body will never succeed on retries, and thus any request with a non-empty body that doesn't succeed the first time will result in an indefinite hang unless it happens to reach MaxAttempts first or be Context-cancelled while making the request.

* Verify that call will return error when Context-cancelled during backoff
* Verify that error is due to Context-cancellation
* Context cancellation would result in no result being sent, thus
  causing the operation to hang in many circumstances
* Add test for POST-requests provided by Do() with a body
* Add test for POST-requests provided by Post() with a body
* Add middlewareServer to support POST tests
* Provide each concurrent request with its own Request so they do not
  interfere with each other. Eg reading/closing each others bodies.
* Reset body before retrying when requests have bodies
Copy link
Owner

@sethgrid sethgrid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for taking the time. these changes all make sense; great pr

@sethgrid sethgrid merged commit 32a1beb into sethgrid:master Feb 9, 2022
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.

2 participants