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 retries #204

Closed
wants to merge 4 commits into from
Closed

Fix retries #204

wants to merge 4 commits into from

Conversation

josharian
Copy link
Contributor

Retries for requests with POST bodies were broken. This fixes them.

Also a tiny bit of cleanup in subsequent commits.

Requests with POST bodies had their bodies
consumed with the first request. If that request
failed and was retried, the body was then empty.
This caused a mismatch with the advertised
Content-Length. Since this is a net/url error,
not an aws.APIError, no further retries were
attempted. As a result, no successful retries
ever occurred.

The fix is simple: Seek back to the beginning
of the body before retrying.
This is more efficient than converting the string
to a []byte.
@euank euank mentioned this pull request Apr 26, 2015
@@ -59,6 +59,9 @@ func ValidateResponseHandler(r *Request) {
}
r.Retryable = r.Service.ShouldRetry(r)
r.RetryDelay = r.Service.RetryRules(r)
if r.Retryable {
r.ResetReaderBody()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking this logic might be bettered suited to a BeforeRetry handler. We already have AfterRetry and Retry handlers so I'm wondering if in this case it would make sense to create a BeforeRetry. What do you think?

@jasdel
Copy link
Contributor

jasdel commented Apr 26, 2015

Thanks for the PR @josharian! What do you think about the idea of using a new BeforeRetry handler instead of ValidateResponse handler for resetting the reader?

@jasdel
Copy link
Contributor

jasdel commented Apr 26, 2015

In #196 the r.Retryable = ... and r.RetryDelay logic was moved to a RetryHandler. It might make sense for r.ResetReaderBody to be there instead a BeforeRetry handler.

@josharian
Copy link
Contributor Author

Thanks for the speedy review.

Using a BeforeRetry handler sounds reasonable. Updated: dc19fa0. If you want a clean commit history, I am happy to squash all the commits if/when you're ready to merge.

Regarding #196, I'm not really sure I understand what is going on there, and I'd like this fix to be orthogonal to it. (And hey, maybe this PR will make the build pass for #196.)

@jasdel
Copy link
Contributor

jasdel commented Apr 28, 2015

Taking a look at both #204 and #196 to address the issue of retry failing.

@josharian
Copy link
Contributor Author

In case it helps, here's a script to test retries by hitting API limits: https://gist.github.com/josharian/b77539174c0ac5a5ca13

@jasdel
Copy link
Contributor

jasdel commented Apr 28, 2015

Thanks @josharian, the script will definitely help.

jasdel added a commit that referenced this pull request Apr 29, 2015
… retry attempts.

Merged #196 and #204 together along with other changes to make sure rewind works in all cases,
Made sure the ordering of handler's setting Request.Retryable vs the Service.ShouldRetry are consitent.
A Request Handler setting Request.Retryable will prevent RetryHandler calling Service.ShouldRetry. The Service's
delay value wills still be applied though.
@josharian
Copy link
Contributor Author

Superceded by #211.

@josharian josharian closed this Apr 29, 2015
jasdel added a commit that referenced this pull request Apr 30, 2015
Fixes retry support to not fail due to body not being rewound between retry attempts. (#204+#196)
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