Skip to content

fix(client): lock async session setup against concurrent callers - #200

Merged
bhearsum merged 3 commits into
mozilla-releng:mainfrom
aminehmida:fix-async-session-race
Aug 17, 2026
Merged

fix(client): lock async session setup against concurrent callers#200
bhearsum merged 3 commits into
mozilla-releng:mainfrom
aminehmida:fix-async-session-race

Conversation

@aminehmida

@aminehmida aminehmida commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

AsyncClient._get_gql_session() assigns _prev_token well before it assigns
the _gql_session that token refers to, with two awaits in between and no
lock. 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-admin
shares one AsyncClient across 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 the
gap 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_concurrent gathers 25 concurrent
_get_aiohttp_session() calls. It fails on main and passes with this change.

The sync client has the same ordering, but SyncClient has no equivalent
interleaving point, so it is left alone.

Comment thread src/simple_github/client.py Outdated
Comment thread src/simple_github/client.py Outdated
Comment thread src/simple_github/client.py Outdated
@aminehmida
aminehmida force-pushed the fix-async-session-race branch from 4a24798 to 6767962 Compare August 17, 2026 10:19
@aminehmida
aminehmida force-pushed the fix-async-session-race branch from 6767962 to 85a4465 Compare August 17, 2026 10:45
@aminehmida

Copy link
Copy Markdown
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 Eijebong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking better, thank you

@bhearsum
bhearsum merged commit 68fa6bb into mozilla-releng:main Aug 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants