-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix request context cancel race when reading response
We had a race between request context cancellation and the reading of the corresponding response. In some circumstances the request context was cancelled before the corresponding response body was read, which resulted in a "context canceled" error. To fix this we create a []context.CancelFunc slice in the routines that call into token-util/DoRetries and we pass-in a pointer to this slice. Then within DoRetries we append each created cancel to this slice. When we return from DoRetries we defer a function to call the cancel functions. In this way we guarantee that we read the response before the corresponding request context is cancelled which fixes the race. We pass-in a slice to ensure that we still comply with the httpclient Do "interface". We've adapted the relevant unit-tests, and also incresed the base httpclient timeout to 120s to allow sufficient time for all retries to be executed.
- Loading branch information
1 parent
d3c8aa0
commit 7f9bdb7
Showing
5 changed files
with
79 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters