fix(client): lock async session setup against concurrent callers - #200
Merged
Conversation
Eijebong
reviewed
Aug 15, 2026
aminehmida
force-pushed
the
fix-async-session-race
branch
from
August 17, 2026 10:19
4a24798 to
6767962
Compare
aminehmida
force-pushed
the
fix-async-session-race
branch
from
August 17, 2026 10:45
6767962 to
85a4465
Compare
Contributor
Author
|
@Eijebong thanks for the extensive review. I think all your points are valid. I have addressed them as best as I can. Please have a look and let me know if it's all good now |
Eijebong
approved these changes
Aug 17, 2026
Eijebong
left a comment
Contributor
There was a problem hiding this comment.
Looking better, thank you
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.
AsyncClient._get_gql_session()assigns_prev_tokenwell before it assignsthe
_gql_sessionthat token refers to, with twoawaits in between and nolock. A caller arriving in that window sees a matching token, takes the reuse
path, and asserts on a session that is still
None.This holds a lock across the whole check-and-build, so the intermediate state
is never observable.
How it showed up
In fxci-config,
ci-adminshares one
AsyncClientacross all its generators. A change there(fxci-config#1124)
started looking up the default branch of ~35 repos concurrently, and 34 of the
35 requests failed with
AssertionError: the first caller was still inside thegap when the rest arrived.
fxci-config carries a local workaround for now, building the session once at
startup while it holds its own lock. It can drop that once this is released.
See fxci-config#1134.
Test
test_async_client_get_session_concurrentgathers 25 concurrent_get_aiohttp_session()calls. It fails onmainand passes with this change.The sync client has the same ordering, but
SyncClienthas no equivalentinterleaving point, so it is left alone.