fix: disable httpx proxy for Photon sidecar localhost connections - #47933
fix: disable httpx proxy for Photon sidecar localhost connections#47933DI404N wants to merge 1 commit into
Conversation
All Photon sidecar HTTP requests target 127.0.0.1 — they should never be routed through a system HTTP proxy. When trust_env=True (the default), httpx picks up macOS system proxy settings and routes localhost requests through the proxy. If the proxy returns a spurious response (e.g. 502), _reap_stale_sidecar() interprets it as 'port in use by a non-sidecar process' and refuses to start, yielding: 'pids: unknown, not a Photon sidecar'. Set trust_env=False on all five httpx.AsyncClient call sites in the Photon adapter so localhost sidecar communication bypasses the system proxy entirely.
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused Photon-sidecar fix. Current main still leaves all five loopback httpx.AsyncClient constructors without an explicit environment-proxy opt-out (plugins/platforms/photon/adapter.py:429, :872, :987, :1550, :1690), and the stale-sidecar probe at :872-886 can treat a non-transport response as an occupied port.
Problems
- The PR adds no regression test for
trust_env=False. The existing reaper fake accepts arbitrary constructor kwargs without inspecting them (tests/plugins/platforms/photon/test_sidecar_lifecycle.py:28-49), so it would not prevent this behavior from regressing.
Suggested changes
- Add a focused constructor-kwargs capture test covering the loopback sidecar clients, at minimum
_reap_stale_sidecarand_standalone_send, and asserttrust_env is False.
The five-hunk patch applies cleanly to current main (git apply --check). This is an automated hermes-sweeper review.
| @@ -667,7 +667,7 @@ async def _reap_stale_sidecar(self) -> None: | |||
| if sys.platform == "win32": # lsof/ps; orphaning is a POSIX-only path | |||
There was a problem hiding this comment.
Please add a regression test that captures the AsyncClient constructor kwargs and asserts trust_env=False for this stale-sidecar health probe; the existing fake client accepts arbitrary kwargs and would not detect a future regression.
|
Merged via #73562 — cherry-picked with authorship preserved and widened to all five sidecar-localhost httpx sites on current main (three grew after your PR). Thanks for the tight diagnosis. |
Summary
All Photon sidecar HTTP requests target
127.0.0.1— they should never be routed through a system HTTP proxy. Whentrust_env=True(the default), httpx picks up macOS system proxy settings and routes localhost requests through the proxy.Bug
If the system proxy returns a spurious response (e.g.
502),_reap_stale_sidecar()interprets it as "port in use by a non-sidecar process" and refuses to start the sidecar:The proxy intercepts the
/healthzPOST and returns 502 → code falls through to_find_listener_pids()→lsofcorrectly finds nothing → "pids: unknown" error.Fix
Set
trust_env=Falseon all fivehttpx.AsyncClient(...)call sites in the Photon adapter so localhost sidecar communication bypasses the system proxy entirely.Reproduced & Tested
127.0.0.1:7890trust_env=Falseresolves the issue — Photon connects immediately