Repository navigation
Throw cancellation in WriteBuffer::next - #109786
Michicosun wants to merge 4 commits into
Conversation
|
Workflow [PR], commit [724fa7f] Summary: ❌
AI ReviewSummaryThis PR makes Missing context / blind spots
Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block
|
|
|
||
| void WriteBuffer::next() | ||
| { | ||
| CurrentThread::checkIfNotCancelled(); |
There was a problem hiding this comment.
WriteBuffer::next is now a cancellation point for every flush, but the TCP handler still uses out->next() to deliver the result of a server-side cancellation on the same query-attached thread. After a timeout or KILL QUERY, the outer handler reaches sendException / finalizeOut (src/Server/TCPHandler.cpp:1095-1143, 3056-3065, 3133-3141), and those paths flush through out->next(). With this new check, CurrentThread::checkIfNotCancelled() throws again before the packet is written, so we fall into the catch (...) { cancelOut(out); return; } path and drop the socket instead of sending the timeout / kill response or preserving the connection.
CancellationChecksBlockerInThread in skipData only fixes the post-error drain. We still need to exempt the protocol writes that must happen after cancellation (sendException, sendEndOfStream, finalizeOut), or keep this cancellation point at a narrower layer than generic WriteBuffer::next.
|
|
||
| if (cancel_reason == CancelReason::TIMEOUT) | ||
| { | ||
| LOG_ERROR(getLogger("QueryStatus"), "Throwing TIMEOUT_EXCEEDED. Stack:\n {}", StackTrace().toString()); |
There was a problem hiding this comment.
QueryStatus::throwProperExceptionIfNeeded is the common cooperative-cancellation path, so this new LOG_ERROR + StackTrace fires for every ordinary timeout and for every worker that notices a KILL QUERY. On a parallel or distributed query that can produce many full stack traces for an expected control-flow event, flooding clickhouse-server.log and adding avoidable work exactly when the query is already timing out. Please keep this behind a temporary debug-only guard or drop it before merge; the same issue applies to the QUERY_WAS_CANCELLED log a few lines below.
|
Dear @Michicosun, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
This patch adds a cancellation point to WriteBuffer::next, let's check how many tests will fail :)