Skip to content

Commit 1aa7ce7

Browse files
Check isCanceled before calling eof on the input ReadBuffer in TCPHandler
When waiting for a new query between requests, `TCPHandler::runImpl` calls `in->eof()` at line 495 to detect client disconnection. If the `ReadBuffer` was previously canceled (e.g., due to a failed read during a prior query's callback), calling `eof()` triggers `next()`, which hits `chassert(!isCanceled())` and aborts the server. Add an `in->isCanceled()` check before `in->eof()` in the condition, matching the pattern already used in `receivePacketsExpectCancel`. Also guard the `in->eof()` call in the `LOG_TEST` message to avoid evaluating it on a canceled buffer (function arguments are not short-circuit evaluated unlike `||`). https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=99537&sha=7338429ff8d3349ba147f9ba05558bbd6b84e4b2&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 49a554c commit 1aa7ce7

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/Server/TCPHandler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,11 @@ void TCPHandler::runImpl()
492492
}
493493

494494
/// If we need to shut down, or client disconnects.
495-
if (!tcp_server.isOpen() || server.isCancelled() || in->eof())
495+
if (!tcp_server.isOpen() || server.isCancelled() || in->isCanceled() || in->eof())
496496
{
497-
LOG_TEST(log, "Closing connection (open: {}, cancelled: {}, eof: {})", tcp_server.isOpen(), server.isCancelled(), in->eof());
497+
LOG_TEST(log, "Closing connection (open: {}, cancelled: {}, in_canceled: {}, eof: {})",
498+
tcp_server.isOpen(), server.isCancelled(), in->isCanceled(),
499+
!in->isCanceled() && in->eof());
498500
return;
499501
}
500502
}

0 commit comments

Comments
 (0)