Repository navigation
Bound the waits of the gRPC fatal error callback on the signal listener thread - #129608
Conversation
…er thread `CallResponder::sendFatalError` runs on the signal listener thread and, while holding the `CallResponder` mutex, waited with no time limit for the write in flight from the call thread and for its own final `FatalError` write. A gRPC write completes only when the client reads, so a client that stops reading blocked the only signal listener thread (no more SIGTERM/SIGHUP handling) and, through the mutex, the call thread. This matters for SIGTSTP, which the server survives; on a real fault the faulting thread gives up after 300 s. Wait for each write at most 10 s, well below those 300 s. On timeout cancel the call, which completes the pending write with `ok = false` (as `close` does), and wait for that. If the in-flight write had to be canceled, do not start the final write on the canceled call: the call thread sees `failed_to_send` and ends the query with NETWORK_ERROR. Closes ClickHouse#129539 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The client takes the first result of `ExecuteQueryWithStreamOutput` and no more while staying connected, so the call thread waits for a write the client never reads. SIGTSTP to the call thread runs the fatal error callback on the signal listener thread; SIGHUP sent afterwards must still be handled (the log file is replaced), and the query must end. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the obvious waitFor comment and shorten the waitWrittenOrCancelLocked comment to its contract. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [4618b12] Summary: ✅
AI ReviewSummaryThe PR limits each client-dependent write wait in Missing context / blind spots
Final VerdictStatus: ✅ Approve |
|
cc @vitlibar, could you review this and add the |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline. |
ab7c840
Closes: #129539
Related: #128018
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
After #128018,
CallResponder::sendFatalErrorruns on the signal listener thread and, while it holds theCallRespondermutex, waits with no time limit for the write in flight from the call thread and for its own finalFatalErrorwrite. A gRPC write completes only when the client reads, so a client that stops taking results blocks the only signal listener thread:SIGTERM,SIGHUPand later faults are no longer handled, and the call thread blocks on the mutex, so the query keeps its resources.As proposed in the issue, each of the two waits now takes at most 10 s, well below the 300 s that a faulting thread waits. On timeout the call is canceled, which completes the pending write with
ok = false, and the callback waits for that. If the in-flight write had to be canceled, the final write is not started on the canceled call; the call thread then sees the failed write and ends the query withNETWORK_ERROR.The new test in
test_grpc_fatal_errorstarts a client that takes the first result ofExecuteQueryWithStreamOutputand then sleeps while staying connected, sendsSIGTSTPto the call thread, and checks that a laterSIGHUPis still handled and that the query ends. On master it fails 4 of 4 runs (grpcio 1.84.0 and the CI pin 1.78.0):SIGHUPis handled only when the client is killed at teardown, about 160 s later. With the fix it passes 61 of 61 runs, withSIGHUPhandled 10.5 s afterSIGTSTP; the rest of the module andtest_grpc_protocolpass.Not for changelog: the case that matters is
SIGTSTP, a debugging signal the server survives (after a real fault the process terminates anyway), and the blocked call thread comes from #128018, which is not in any release.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/129608]
Version info
26.11.1.1547-master(included in26.11and later)