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: correctly handle exceptions >400 #79

Merged
merged 8 commits into from
Feb 14, 2020
Merged

Conversation

whickman
Copy link
Contributor

@whickman whickman commented Feb 12, 2020

Before this PR

error handling for codes >=400 was incorrect because of the error decoding middleware

After this PR

==COMMIT_MSG==
Fixes #78
Extracts status code from the returned error and acts on that. This limits more complex behavior, such as respecting the retry-after header.
==COMMIT_MSG==

Possible downsides?

The longer-term solution, which in my opinion is preferable, is to move retry logic into middleware below the error decoding middleware and out of the client directly. This will allow it to inspect the response before it gets filtered by the error decoding middleware.

Unfortunately, this is not possible given that we currently support arbitrary error decoders and retry behavior is dependent on whether an error is returned or not. Doing error decoding after retrying will therefore be a behavior break and will cause user-defined "errors" to no longer be retried.


This change is Reviewable

@whickman
Copy link
Contributor Author

opened follow-up issues #80 and #81

Copy link
Contributor

@ryanmcnamara ryanmcnamara left a comment

Choose a reason for hiding this comment

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

I'm concerned about the behavior change of a specific use case that this change will cause

  • default client configuration
  • one url configured

Before this change, on 429 we would actually not retry
After this change we will retry the same url twice on 429, which I would argue is strictly worse

conjure-go-client/httpclient/client.go Show resolved Hide resolved
conjure-go-client/httpclient/client.go Show resolved Hide resolved
conjure-go-client/httpclient/failover_test.go Show resolved Hide resolved
@whickman
Copy link
Contributor Author

re high-level concern: I don't think that's correct @ryanmcnamara , it would immediately retry because it would hit the resp == nil branch

@ryanmcnamara
Copy link
Contributor

ryanmcnamara commented Feb 13, 2020

Ah.. I see that.. makes sense

Really do want to improve that, but obviously out of scope here for this pr

// If we get a nil response, we can assume there is a problem with host and can move on to the next.
nextURI, offset = nextURIOrBackoff(nextURI, uris, offset, failedURIs, retrier)
} else if shouldThrottle, _ := internal.IsThrottleResponse(resp); shouldThrottle {
if retryOther, _ := internal.IsThrottleResponse(resp, err); retryOther {
Copy link
Contributor

Choose a reason for hiding this comment

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

These if blocks are are reordered now.. I guess there is no functionality change though? Can you confirm?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, this does matter now because the resp == nil case is true for both this statement and the following one. The test I added will fail if the order changes

Copy link
Contributor Author

@whickman whickman left a comment

Choose a reason for hiding this comment

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

yeah I agree, but I think it's worth pulling that out of the critical path. The other two issues I opened track the follow ups from this work

@ryanmcnamara
Copy link
Contributor

👍

Copy link
Contributor

@ch-plattner ch-plattner left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 3 files at r1, 5 of 7 files at r3, 1 of 1 files at r4, 1 of 1 files at r5.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ryanmcnamara and @whickman)

@bulldozer-bot bulldozer-bot bot merged commit 9f720b3 into develop Feb 14, 2020
@bulldozer-bot bulldozer-bot bot deleted the wh/simple-fix branch February 14, 2020 20:58
@svc-autorelease
Copy link
Collaborator

Released 0.4.1

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

Successfully merging this pull request may close these issues.

Consider Supporting 429 Throttling
6 participants