Skip to content

Bound the waits of the gRPC fatal error callback on the signal listener thread - #129608

Merged
CheSema merged 3 commits into
ClickHouse:masterfrom
groeneai:grpc-fatal-error-bounded-writes-v2
Nov 6, 2026
Merged

CheSema merged 3 commits into
ClickHouse:masterfrom
groeneai:grpc-fatal-error-bounded-writes-v2

Conversation

@groeneai

@groeneai groeneai commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #129539
Related: #128018

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Description

After #128018, CallResponder::sendFatalError runs on the signal listener thread and, while it holds the CallResponder mutex, waits 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 taking results blocks the only signal listener thread: SIGTERM, SIGHUP and 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 with NETWORK_ERROR.

The new test in test_grpc_fatal_error starts a client that takes the first result of ExecuteQueryWithStreamOutput and then sleeps while staying connected, sends SIGTSTP to the call thread, and checks that a later SIGHUP is 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): SIGHUP is handled only when the client is killed at teardown, about 160 s later. With the fix it passes 61 of 61 runs, with SIGHUP handled 10.5 s after SIGTSTP; the rest of the module and test_grpc_protocol pass.

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

  • Merged into: 26.11.1.1547-master (included in 26.11 and later)

groeneai and others added 3 commits November 5, 2026 18:37
…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]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4618b12]

Summary: ✅


AI Review

Summary

The PR limits each client-dependent write wait in CallResponder::sendFatalError to 10 seconds before cancelling the RPC and draining its pending completion. It adds a regression test that checks signal handling and query cleanup with a connected client that stops consuming results. No actionable correctness or safety findings at commit 4618b1285ba592c5f2b3908155c930c42284f7db.

Missing context / blind spots
  • ⚠️ Integration tests could not be run locally because this checkout has no ClickHouse binary or build directory. The PR reports four failing baseline runs and 61 passing runs with the fix; independent confirmation awaits the test_grpc_fatal_error result in CI, which is still pending.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Nov 5, 2026
@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

cc @vitlibar, could you review this and add the can be tested label so CI runs? On a fatal signal, the gRPC callback on the signal listener thread now waits at most 10 s for each pending write and then cancels the call, so a client that stops reading no longer blocks signal handling.

@clickhouse-gh clickhouse-gh Bot added can be tested Allows running workflows for external contributors comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... labels Nov 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4618b1285 with master 561973a15 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline.

Job report

@CheSema CheSema self-assigned this Nov 6, 2026
@CheSema
CheSema added this pull request to the merge queue Nov 6, 2026
Merged via the queue into ClickHouse:master with commit ab7c840 Nov 6, 2026
547 of 549 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gRPC: the fatal error callback can block the signal listener thread forever when the client does not read

3 participants