Repository navigation
Serialise GLPI v1 session renewals so concurrent requests open and kill the session once - #50
Merged
Merged
Conversation
…ll the session once A client shared by concurrent tasks or threads renewed the v1 session once per request that found the token stale, on the first lazy initSession, and after a 401 or 403 rejection. Each renewal killed the token and opened a session: the second killSession answered 401, and the first new session was overwritten and never killed, leaking one server-side session per renewal. Every acquisition now takes a lock (the library's auth Lock type) and re-checks under it whether the work is still needed: token still missing, still stale, or still the very token the failed request used. Waiters reuse the token the first renewal obtained. Only _ensure_session, _renew_rejected_session and close take the lock, and none calls another, so the non-re-entrant sync lock cannot deadlock. The retry decorators are unchanged. Tests are hand-written on both sides (task bursts on the async tree, thread bursts on the sync tree) and fail without the lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #50 +/- ##
==========================================
+ Coverage 98.11% 98.16% +0.05%
==========================================
Files 96 96
Lines 3811 3823 +12
==========================================
+ Hits 3739 3753 +14
+ Misses 72 70 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Nov 23, 2026
Merged
Merged
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
GLPIV1Sessionrenewed its token without any lock. A client shared by concurrent tasks or threads hit three races:killSessiontheninitSession;The second
killSessionanswered 401, the first new session was overwritten and never killed (one leaked server-side session per renewal), and requests in flight could be sent with a token that had just been killed.Fix
_session_lock(the library's_concurrency.Lock:asyncio.Lockon the async surface,threading.Lockin the sync twin) serialises acquisition._ensure_session,_renew_rejected_sessionandclosetake the lock, and none calls another or_headerswhile holding it, so the non-re-entrant sync lock cannot deadlock.close()still kills the current session and releases the HTTP client.unasync_build.py.Tests
Hand-written on both trees (task bursts on async, thread bursts on sync), listed in
HAND_WRITTEN. They cover stale renewal, concurrent first use, concurrent rejections of one token, andclose()after a renewal, and assert exactly onekillSessionand oneinitSessionper renewal, all requests on the new token and no leaked session. All fail without the lock.pytest -m "not integration"(2316 passed),ruff check,ruff format --check,mypy,unasync_build.py --checkand the sphinx-Wbuild pass.🤖 Generated with Claude Code