Repository navigation
fix(sandbox): close the client when the idle L7 upstream closes - #5
Open
kosaku-sim wants to merge 2 commits into
Open
kosaku-sim wants to merge 2 commits into
kosaku-sim wants to merge 2 commits into
Conversation
Regression tests for the REST (inspection) and credential-passthrough relays: after keep-alive exchanges, closing the upstream (or the upstream sending unsolicited bytes) must end the relay and close the client side. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The REST and credential-passthrough relays only waited for the client's next request, so an upstream idle close (api.github.com closes idle keep-alive connections after 30s) never reached the client. The client kept the pooled connection, its next request hit the dead upstream and the connection was dropped with no response (gh: Post .../graphql: EOF). Watch the idle upstream while waiting for the next request and end the relay as soon as it reports EOF, an error or unsolicited bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
概要
L7 relay(
relay_restとrelay_passthrough_with_credentials)は、クライアントの次のリクエストだけを待ち、その間に upstream が接続を閉じても気づかなかった。upstream が keep-alive の idle 接続を閉じても、proxy はクライアント側を開いたままにする。クライアントはその接続をまだ使えると見て次のリクエストを送り、proxy は応答を返さずに切断していた。次のリクエストを待つ間は upstream も同時に読み、EOF・エラー・予期しないデータのどれかが来たら relay を終える。これでクライアント側も閉じる。クライアントはその接続を pool から外して新しく張り直すので、proxy を通さないときと同じ動きになる。
きっかけ
AutoDev の受入テストの証跡を
gh pr edit --attach(42 件)で PR 本文に添付すると、Post "https://api.github.com/graphql": EOFで失敗していた。gh は最初に api.github.com へ接続して PR を読み、添付を uploads.github.com へ upload(約 65 秒)したあと、最初の接続を使い回して本文を更新する。api.github.com は idle 30 秒で接続を閉じる。proxy がそれをクライアントに伝えないので、最後の更新が応答なしで切られていた。Go のnet/httpは POST を送り直さない。実測(sandbox から proxy 経由、api.github.com へ GET のあと N 秒空けて 2 本目を送る):
proxy を通さずに直接つなぐと、GitHub は 30.0 秒で FIN を送り、Go は次のリクエストを新しい接続で送る(
reused=false)。upstream(NVIDIA/OpenShell main、2026-11-05 時点)でも、この 2 つのループは同じ作りのまま。似た症状の NVIDIA#3724(NVIDIA#3772 で修正)は
forward serviceの経路が対象で、egress の L7 relay は含まない。変更内容
next_request_unless_upstream_closed:tokio::select!でparse_request(client)と upstream の 1 byte read を同時に待つ。upstream 側が先に終わればNoneを返す。どちらの read も cancel safe(AsyncReadExt::read/read_u8は、完了前に drop しても読んだデータを失わない)relay_restとrelay_passthrough_with_credentialsの待ち受けをこの関数に置き換えるテスト
l7::relay::testsに 3 件追加。REST relay と passthrough relay それぞれで、keep-alive の往復 2 回のあと upstream を閉じると relay が終わり、クライアントが EOF を受ける。upstream が idle 中に予期しないデータ(408)を送ったときも同じ6df0661)では 3 件とも timeout で失敗し、修正後(d05e3ea)は通ることを確認したcargo test -p openshell-sandbox --lib: 461 件通過、失敗 2 件。失敗した 2 件は修正前の commit でも同じく失敗する環境依存のテスト(baseline_tests::enrich_proto_baseline_paths_adds_pty_paths_for_proxy_modeは/sandboxが無いと失敗、process::tests::drop_privileges_succeeds_for_current_userは root 以外で失敗)cargo fmt --check: 今回の変更による差分なし(既存のchild_env.rs/netns.rs/secrets.rsの差分は残る)cargo build --release -p openshell-sandbox。sha256f3981a1e353de353e5a45182a3a8f89b2b65c380484cdd5d77a86a49232259d9配布
/opt/openshell/bin/openshell-sandboxを差し替え、sandbox pod を作り直した。上の実測の「修正後」は kosaku-1 で測ったものshared/binaries/openshell-sandbox-aarch64)と pf-1 は未反映🤖 Generated with Claude Code
https://claude.ai/code/session_01EAuXbos6RUPVHwYrmQ3HQf