Fix request context cancel race when reading response #130
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We had to fix the trivy scan GH action to pull the latest version of the
action as opposed to master.
Signed-off-by: Eamonn O'Toole [email protected]