Repository navigation
Conversation
KeeperDispatcher::shutdown drained the dispatcher queues and asserted that they accounted for zero bytes, and only afterwards called server->shutdown(). But responses are produced by NuRaft's commit thread (KeeperStateMachine::commit -> KeeperRequestDispatcher::onResponse), and only server->shutdown() joins it. The check therefore sampled a quiescence property while a producer was still running: a commit landing in that window pushes a response and increments response_bytes_in_all_queues after the drain, so the assertion fired in debug and sanitizer builds. The request side is unaffected because putRequest already returns early once shutdown is called, which is why the sibling requests_queue_bytes assertion was never the one failing. There is a second leak on the same path. After the check, shutdown appends session Close requests to Raft and waits only for them to reach the leader. Their responses arrive later, with response_thread already joined, so nothing ever drained them. Shutdown is now split into shutdownRequests() and drainAndCheckQueues(), called around server->shutdown(), so the check runs only once every producer is quiesced. This also drains the Close responses that used to leak. A split is required rather than a swap: shutdownRequests needs a live raft_instance to send the Close requests, and KeeperServer::shutdown destroys it. Both assertions are preserved unchanged; no new setting, timeout or threshold is introduced. The failure showed up as an integration test failing at cluster.shutdown() with "Crash in instance", on whichever test happened to be tearing its cluster down. The window is only a few atomic loads wide, hence no master sightings and only sanitizer builds affected. The new integration test widens it with the keeper_shutdown_delay_before_queue_check failpoint, keeps writes in flight while the leader is stopped, and asserts that no accounting logical error appears. It fails on master and passes with this change.
The regression test only asserted the absence of the accounting logical error. That also holds when the checks never run, so it could not distinguish this fix from a build where drainAndCheckQueues is never called or its assertions are gone. drainAndCheckQueues now logs a fixed marker where it performs the checks, and the test asserts that the marker is present and that it follows nuraft's "commit thread stopped." line, which is the ordering this fix establishes. NuRaft already logs that line at the raft_logs_level this suite configures, so no production change is needed for the ordering half. Also drop a clause from the startup-error path comment. On that path initialize rethrows, so the dispatcher is never stored in the Context and KeeperDispatcher::shutdown is not called through it later. The behaviour was already correct; only the stated reason was wrong.
test_session_close_shutdown pointed at a TODO in KeeperRequestDispatcher::shutdown, which this branch splits into shutdownRequests() / KeeperServer::shutdown() / drainAndCheckQueues(). The TODO it refers to now lives in shutdownRequests, so point there. Comment only, no behaviour change. Co-Authored-By: Claude Fable 5 <[email protected]>
The regression test pinned the shutdown ordering and the absence of the accounting logical error, but not that the drain performed after nuraft's commit thread is joined actually removes anything, so it still passed with that drain deleted. The window that drain exists to cover is not the few hundred microseconds between the dispatcher's own drain and the nuraft join, but the wait inside shutdownRequests for the session Close entries to reach the leader, which can last up to session_shutdown_timeout. By then both dispatcher threads are joined, so responses_queue has no consumer while nuraft's commit thread is still publishing into it, and those bytes survive until the final drain. Reuse keeper_shutdown_delay_before_queue_check at a second site, at the end of shutdownRequests, so a test can open that window; return the released byte count from drainQueues and report it on the existing marker line; assert it is nonzero. Deleting the final drain now reproduces the original assertion failure instead of passing silently. Both assertions stay byte-identical and the failpoint remains inert when disabled. Also correct a comment: on the measured path the Close responses are never produced, because raft_server::shutdown sets stopping_ before waiting for the commit thread, so commit_in_bg_exec returns early and the state machine never commits those entries. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Reviewed internally over 4 rounds before opening. Everything merge-relevant from those rounds is in |
Validation summary (click to expand)Repro. A bare rerun does not reproduce: the drain-to-check window is a few atomic loads, which is Both directions. Merge-base source, with the same failpoint injected at its own drain-to-check Generality. All 5 counter mutation sites enumerated. Session id: cron:clickhouse-review-slot-9:20260730-211400 |
|
Workflow [PR], commit [7232670] Summary: ✅
AI ReviewSummaryThis PR splits Keeper shutdown so the dispatcher stops intake first, Final VerdictStatus: ✅ Approve LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 47/48 (97.92%) · Uncovered code |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 47/48 (97.92%) · Uncovered code |
CI finish ledger: 3f7020cCI is fully finished (174 check-runs, none queued). Every failure has an owner, and none is caused by
Session id: cron:our-pr-ci-monitor:20260731-040000 |
|
@groeneai please edit the comments down to ~1/5 the current total length. |
|
Done. My comments on this PR went from 17363 to 3541 characters, a bit under a fifth. What went is the |
|
Fixing PR for the That failure was not caused by this PR. The fuzzer had mutated the in-tree test Verified on two real binaries: the pre-fix debug build ( |
|
Fixing PR for the Two corrections to that row. The stack fragment I quoted from The query that actually hung is |
…-bytes-shutdown-assert
|
Backport ask: @alexey-milovidov, could you apply This fix is absent from 26.6 and 26.7, and the assertion it removes fired again on 26.7 last night: Keeper aborted at Per branch: master and 26.8 have the fix (26.8 was cut 20 days after this merged, so it inherited it); 26.7 and 26.6 carry the To be accurate about what this buys: The port looks cheap. A three-way apply of this diff is clean on both branches, the result orders If a shutdown-ordering change in two stable branches is not worth a CI-only benefit, that is a fine answer and I will drop it. |
Pull in the fix for the Keeper logical error `response_bytes_in_all_queues.load() == 0` on shutdown (ClickHouse#112668), which was the only red check on the previous head.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
KeeperDispatcher::shutdowndrained the dispatcher queues and checked that they accounted for zerobytes, and only then called
server->shutdown(). But responses are produced by NuRaft's commit thread(
KeeperStateMachine::commit->KeeperRequestDispatcher::onResponse), and onlyserver->shutdown()joins it, so the check sampled a quiescence property while a producer was still running.
Shutdown is now split so the check runs only once every producer is quiesced:
shutdownRequestsstopsintake, joins the dispatcher's own threads and submits the session
Closerequests;KeeperServer::shutdownjoins NuRaft (raft_server::shutdownspins until the commit thread hasterminated, so the join is a hard guarantee);
drainAndCheckQueuesthen drains and checks both queues.A split rather than a swap is required: the first phase needs the live
raft_instancethatKeeperServer::shutdowndestroys. Both assertions are unchanged; no new setting, timeout or thresholdis introduced.
chassertcompiles to nothing outside debug and sanitizer builds, and the counter's remaining readersbelong to threads that are already joined at this point, so this is a test-only failure rather than
user-visible misbehavior, hence the CI category.
Found in CI 3 times across 3 unrelated PRs in 60 days, never on master. The new integration test uses a
failpoint added here to widen the window in which the dispatcher's own consumer threads are joined while
NuRaft is not, stops the leader under load, and asserts that no accounting logical error appears, that
the queue check ran after the Raft join, and that the drain performed after that join released a nonzero
number of response bytes. The ordering and byte-count assertions matter because on the
arm_binaryintegration job, where
chassertcompiles away, they are the only ones that can fail. Deleting thepost-join drain, or restoring the old ordering, each reproduces the original logical error; removing the
check itself reddens the ordering assertion instead.
CI provenance
Observed on
Integration tests (amd_tsan, 3/6)andIntegration tests (amd_msan, 3/8). Report forone of them, PR #110627 at commit
dcb02553e49f08659bcb9d40fdf6e57f70ce0997:https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110627&sha=dcb02553e49f08659bcb9d40fdf6e57f70ce0997&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%203%2F6%29
#112088 edits two timeout expressions inside the block
that moves here, so whichever merges second needs a trivial keep-both resolution.
Version info
26.8.1.728(included in26.8and later)