Repository navigation
Respect cancellation while waiting for a connection in ConnectionLimitingPool - #406
Merged
Merged
Conversation
…tingPool A request waiting for the connection of another request ignored its own cancellation, so a chain of failing connections to one authority couldn't be left: 2 of 500 requests finished in 40 s, all 500 are cancelled on time with this change.
Member
|
Thanks! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
On https a request waits for connections that other requests are establishing, because the first one may turn out to be
HTTP/2. That wait, like the others in
getStreamFor(), ignores the cancellation of the request.So a request to a host that can't be reached stays stuck behind everyone else's connection attempts, whatever its
timeout. Sending 500 requests with a 10 s
TimeoutCancellationto a host that doesn't resolve, only 2 finished in 40 s.Solution
Pass
$cancellationto the awaits ingetStreamFor(), and rethrow it in thecatchthat ignores failures of otherrequests. The background callback in
EventLoop::queue()is unchanged: it has to finish regardless of who cancels.With the change, all 500 requests are cancelled at 10 s, with a peak of 18 MB. A healthy HTTP/2 host still gets 3
connections for 300 concurrent requests, as before.
There are two new tests.
testCancellationWhileWaitingForConnectionOfAnotherRequestfails without the fix.testEstablishedConnectionIsCountedAsOpencovers what no test checked so far: the state of the pool after a connectionis established. An error in that callback only showed up as a lost connection.