fix: use explicit session for all threads when provided #3800
+95
−6
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.
Summary
Fixes #3789
When a
sessionis explicitly provided toHTTPProvider, it should be used for all requests regardless of which thread makes them. Previously, the session was cached with a thread-specific key (threading.get_ident()), so other threads/greenlets would create their own sessions, defeating the purpose of providing a shared session.Changes
HTTPSessionManager: Addedexplicit_sessionparameter. When set,cache_and_return_session()returns it directly, bypassing the thread-based cache.HTTPProvider: Pass the user'ssessionto the manager constructor instead of caching it post-construction.Impact
This is critical for applications using:
Without this fix, a setup with 5000 greenlets could create up to 5000 separate
requests.Sessioninstances, each with its own connection pool, leading to thousands of unclosed RPC connections.Test Plan
test_user_provided_session_shared_across_threads- verifies explicit session is used by all threadstest_no_explicit_session_creates_per_thread_sessions- verifies default behavior unchanged