ref(apigateway): use a threadlocal session for proxy requests#116054
Merged
Conversation
66090ab to
3cf4267
Compare
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3cf4267. Configure here.
3cf4267 to
d76fe99
Compare
Create the pooled API gateway requests session on first use in each thread so rollout-enabled proxy requests do not fail in worker threads. Register the API gateway pooling rollout option and apply it through the existing random rollout helper. Co-Authored-By: Codex <noreply@openai.com>
d76fe99 to
46383d6
Compare
markstory
approved these changes
May 22, 2026
Member
markstory
left a comment
There was a problem hiding this comment.
Looks good to me. The cookie jar implementation you have will prevent cookies from proxied requests from being stored. I read through requests' docs and didn't see any other attributes that would be retained across requests.
Release streamed upstream responses after Django finishes proxying so pooled sessions do not hold sockets or file descriptors after the response lifecycle ends. Add test cleanup for the thread-local sync proxy session to keep pooled connection state isolated between tests. Co-Authored-By: Codex <codex@openai.com>
… tests Select the request callable once (pooled session vs. one-off request) instead of duplicating the full request call across both branches. Drop the production-only close_connection() helper, which was only ever used for test cleanup, and inline that teardown into the test fixture so the proxy module no longer carries test-only API. https://claude.ai/code/session_01WKg4JcWqqoM19sJ7BSqC98
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.

Use a rollout-gated, thread-local
requests.Sessionfor synchronous API gateway proxy requests so the gateway can reuse HTTP connections without sharing a session object across request-handler threads. Same as #115827 which we saw helped quite a bit with RPC latency, but on our api gateway cross silo requests.Slack Context: https://sentry.slack.com/archives/C0B40RRUCT0/p1779391427679709
Rollout Control
Pooling now uses
hybridcloud.apigateway.use_pooling.rateas a sampled rollout rate, matching the RPC pooling rollout behavior instead of treating any non-zero value as full enablement.Cookie Handling
The pooled session uses a stateless cookie jar so backend
Set-Cookieheaders are still returned to the client, incoming requestCookieheaders are still forwarded to the cell, and response cookies are not remembered for later requests on the same thread.