fix(tokens): claim redis socket tokens atomically#6771
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
Greptile SummaryThis PR fixes a race condition in
Confidence Score: 5/5Safe to merge — the change is a well-scoped, targeted fix to a real concurrency bug in the Redis token-claim path with no regressions to the local fallback or disconnect logic. The atomic SET NX approach is the standard Redis idiom for this pattern and is applied correctly. All three exit paths from No files require special attention. Important Files Changed
Reviews (3): Last reviewed commit: "fix(tokens): address atomic claim review" | Re-trigger Greptile |
|
Hi appreciate the contributions but can you prioritize Github issue also please address the AI review before marking it out of draft |
Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
553fbf1 to
3e0cf0f
Compare
All Submissions:
Type of change
Description
RedisTokenManager.link_token_to_sidpreviously checked whether a token existedbefore storing its socket record in a separate Redis command. Concurrent workers
could both observe an absent token and then associate it with different sockets,
allowing two connections to share the same client state.
This change claims each token with an atomic Redis
SETusingNXand the existingexpiration. A worker that loses the claim retries with a new UUID, while Redis
errors continue to use the local token-manager fallback.
The regression test coordinates two managers against shared Redis state and verifies
that only one keeps the requested token. It fails against the previous implementation
and passes with the atomic claim.
Testing
uv run pytest tests/units/utils/test_token_manager.py -q(28 passed, 4 skipped)uv run pytest tests/units --cov --no-cov-on-fail --cov-report=(6625 passed,17 skipped, 78.04% coverage)
uv run ruff check .uv run ruff format . --checkuv run pyright reflex tests(0 errors)uv run towncrier check --config pyproject.toml --compare-with origin/mainChanges To Core Features: