Skip to content

Commit f694fc0

Browse files
committed
test(network): keep the CONNECT handler test client fork-free
The handler regression tests forked cat to read the proxy reply, so the client socket fd was inherited by a second process with a different binary. The identity resolver correctly denies that as ambiguous shared-socket ownership (the same invariant resolve_process_identity_denies_fork_exec_shared_socket_ambiguity pins), so the tests exercised the deny path instead of the allow path — and on busy CI runners the deny-path /proc fallback scan exceeded the test budget and looked like a hang. The client script now uses only bash builtins (exec, printf, read -d '') so exactly one process owns the socket, and the child is left to exit on EOF instead of being killed mid-read. Signed-off-by: Tony Luo <[email protected]>
1 parent 0148b41 commit f694fc0

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

  • crates/openshell-supervisor-network/src

‎crates/openshell-supervisor-network/src/proxy.rs‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8024,14 +8024,18 @@ network_policies:
80248024
let proxy_port = listener.local_addr().unwrap().port();
80258025

80268026
// The child connects, sends the CONNECT request, then reads the proxy's
8027-
// reply to EOF. `cat` keeps the socket ESTABLISHED while the proxy
8028-
// resolves identity, then surfaces whatever bytes the proxy wrote.
8027+
// reply to EOF and prints it. Everything is a bash builtin (exec,
8028+
// printf, read) so NO external command is forked — a forked `cat`/`head`
8029+
// would inherit the socket fd, making the inode owned by two PIDs with
8030+
// different binaries, which the resolver correctly denies as ambiguous
8031+
// shared-socket ownership. `read -d ''` reads all bytes up to EOF into
8032+
// `resp`; on EOF it returns non-zero but `resp` still holds the reply.
80298033
let script = format!(
80308034
"exec 3<>/dev/tcp/127.0.0.1/{proxy_port}; \
80318035
printf 'CONNECT {connect_target} HTTP/1.1\\r\\nHost: {connect_target}\\r\\n\\r\\n' >&3; \
8032-
cat <&3",
8036+
IFS= read -r -d '' resp <&3; printf '%s' \"$resp\"",
80338037
);
8034-
let mut child = Command::new(&bash)
8038+
let child = Command::new(&bash)
80358039
.arg("-c")
80368040
.arg(&script)
80378041
.stdin(Stdio::null())
@@ -8064,7 +8068,10 @@ network_policies:
80648068
.await
80658069
.is_ok();
80668070

8067-
let _ = child.kill();
8071+
// Do not kill the child: it exits on its own once the server socket is
8072+
// dropped (normal return or timeout), at which point its read sees EOF
8073+
// and it prints whatever the proxy wrote. Killing it here would race
8074+
// that final read and truncate the captured response.
80688075
let output = child.wait_with_output().expect("collect child output");
80698076
(completed, output.stdout)
80708077
}

0 commit comments

Comments
 (0)