Repository navigation
Do not let a stateless test take the harness's bash xtrace descriptor - #115917
Conversation
05024_local_listener_survives_handler_exception exits 141 on Fast test (arm_darwin). 141 is 128 + 13, i.e. death by SIGPIPE, and the cause is a descriptor collision with the test harness itself. shell_config.sh opens the bash xtrace log on fd 3 and points the tracer at it with BASH_XTRACEFD=3. The test then did `exec 3<>/dev/tcp/...`, which closes that log and rebinds fd 3 to the ClickHouse native port, so bash writes every xtrace record into the socket. The test sends HEAD precisely so the server treats it as an unexpected packet and closes the connection, which is the scenario under test; the tracer's next write then lands on a closed socket and the shell itself takes the signal. Because the fatal write is the tracer's, the death belongs to no command in the script, and the trace stops at the line that stole its descriptor, which is why both CI bashlogs end mid-script at that exec rather than at the point execution actually stopped. CI passes --trace, so this half is live on the failing check. No pipefail is involved. Letting bash allocate the descriptor removes the collision: the first auto-assigned fd is 10, so it can collide neither with the harness's fd 3 nor with stdin/stdout/stderr. 04306_insert_stream_timeout_flush_http_input.sh already writes it this way. SIGPIPE is ignored around the poke because the peer going away is the expected outcome of the scenario rather than a failure, and the write's stderr is discarded because clickhouse-test fails a test on any non-empty stderr, so a surviving "write error: Broken pipe" would only trade one red for another. `|| true` does not work here: the signal kills the shell before the || list is evaluated. The collision is platform-independent, and every traced run hijacks the descriptor; what differs is whether the peer closes early enough for a tracer write to land on a dead socket. Against a peer that closes on accept this reproduces 60/60; against a real clickhouse-local native port on Linux it needs an extra write to become deterministic, which is consistent with the failure being seen on macOS only. The precise reason darwin loses that race more often is not measured and is not claimed. The hijack had a second consequence: on runs where the connection stayed up, the tracer's records went into the native port too, so the packet the server received was xtrace text wrapped around the intended HEAD. The test's premise of sending exactly one unexpected packet therefore did not hold on any traced run, including the passing ones. That is why this changes the descriptor instead of merely tolerating the signal. The reference output is unchanged, and the fixed test still fails against a pre-115715 binary, so the oracle it exists for is intact. Related: ClickHouse#115715
Internal second-model review: 0 blockers, 0 majors, 2 nits (1 fixed, 1 noted)Two independent reviews of this diff: a cold code review, and a second-model gate pass Verified against the tree rather than taken on trust:
Session id: cron:clickhouse-review-slot-8:20260822-141502 |
Pre-PR validation gate (a-i)
Negative controls (the fix must not disarm the test). Against a pre-#115715 binary, i.e. the state Randomized runs. 150/150 green: 50 with randomized settings and |
|
Workflow [PR], commit [17532e9] Summary: ✅ AI ReviewSummaryThis PR fixes Final Verdict
|
|
cc @alexey-milovidov, could you review this? The test took fd 3 for its |
0abbc75
Related: #115715
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
05024_local_listener_survives_handler_exceptionexits141onFast test (arm_darwin). It landed with#115715 and reddened four unrelated PRs in one 2h20m window;
Fast testgates every PR. Two of those runs:report 1,
report 2.
141is128 + 13, death bySIGPIPE, from a descriptor collision with the harness itself.shell_config.shopens the bash xtrace log on fd 3 and setsBASH_XTRACEFD=3. The test then didexec 3<>/dev/tcp/..., closing that log and rebinding fd 3 to the native port, so bash wrote every xtracerecord into the socket. The test sends
HEADprecisely so the server rejects it as an unexpected packet andcloses the connection, and the tracer's next write lands on a closed socket. That also explains the
bashlogs ending mid-script: the line that stole the descriptor is the last thing the trace could record, so
the truncation points at the hijack, not at where execution stopped.
The fix lets bash allocate the descriptor (
exec {sock}<>..., as04306_insert_stream_timeout_flush_http_input.shalready does) and ignoresSIGPIPEaround a poke whosewhole point is that the peer goes away.
|| truedoes not work here: the signal kills the shell before the||list is evaluated.Every traced run hijacks the descriptor on Linux too; only whether the peer closes early enough to be
fatal is racy, hence macOS. And because the tracer shared the socket, the packet the server received was
xtrace text wrapped around the intended
HEAD, so this is a descriptor fix, not signal tolerance. Onlythis test collides, so the harness is unchanged.
Validation: 60/60
141before and 60/60 clean after on the isolated mechanism, 10/10 to 10/10 against areal
clickhouse-localnative port, 150/150 green across randomized andFast test-shaped runs. The fixedtest still fails against a pre-#115715 binary, so it is not disarmed.
Workflow [PR]
Sync PR [sync-upstream/pr/115917]
Version info
26.8.1.1922(included in26.8and later)