Repository navigation
fix: don't count time blocked on a slow consumer against ReadTimeout - #2063
Conversation
|
CI hasn't run here yet, I think it needs approval since this is my first PR. Could someone kick it off when there's time? |
🤖 Claude reviewResets the native read deadline after each data block is given to the consumer, so the time that the reader waits on a slow What I checked:
Remaining limit (not a blocker): only data blocks with rows reset the deadline. Progress, log, and profile-event packets do not. A query for which the server sends only such packets for longer than Blind spots: I did not run the tests. I did not confirm with a live server that the Verdict: ✅ Approve Inline comments are attached to the relevant lines. This summary updates in place on re-review. |
chernser
left a comment
There was a problem hiding this comment.
@ninadsutrave
please add reset on empty blocks:
Long scan with selective WHERE: If ClickHouse scans data for longer than ReadTimeout while emitting only 0-row ServerData blocks, PR does not reset ReadTimeout because c.startReadWriteTimeout(ctx) sits inside if block.Rows() != 0 && on.data != nil. Moving the reset outside that if (at the end of the ServerData, ServerTotals, ServerExtremes case, when on.data != nil) would cover empty data blocks as well without touching progress or log packets.
|
Done, the reset now runs for every data block, empty or not. While testing it, though, I couldn't get the server to send empty blocks for a selective scan. With If you want that case covered, the reset would need to run on Progress packets too. That changes ReadTimeout from "time between blocks" to "time the server is silent", so I've left it out for now. Happy to add it here or in a follow-up if you'd prefer. |
|
This is fine. Thank you for the update. |
Summary
Fixes #1672.
On the native protocol the read deadline for a query's result stream is set once, before the read loop. When a
rows.Next()consumer is slow, the stream channel fills and the reader blocks insideon.datawhile that deadline keeps running, so the next socket read fails withi/o timeouteven though the server responded promptly.The read deadline is now reset after a data block has been handed to the consumer, so time spent waiting on the consumer no longer counts. A query that keeps the server busy past
ReadTimeoutbefore sending data, such asSELECT sleep(3)with a 1s timeout, still fails as before. Once blocks are flowing, each one restarts the timeout, so a long result that keeps streaming is no longer cut off by its total duration; a context deadline still applies and takes precedence.tests/issues/issue_1672_test.gocovers both cases: a slow consumer reading a multi-block result (fails withi/o timeoutbefore, passes after) and a slow server query (times out both before and after).Checklist
Note
Medium Risk
Touches native protocol read-loop timeout behavior for all streaming queries; wrong reset logic could mask slow servers or cause hung reads.
Overview
Resets the connection read deadline after each data block is delivered to the query consumer (including empty blocks), so idle time waiting on a slow
rows.Next()loop no longer burns the configuredReadTimeoutwhile the server has already sent data.Adds issue #1672 regression tests: a slow consumer over a long multi-block
SELECTmust complete when total wall time exceedsReadTimeout, while aSELECT sleep(3)with a 1sReadTimeoutstill fails withos.ErrDeadlineExceeded.Reviewed by Cursor Bugbot for commit ebe1d3a. Bugbot is set up for automated code reviews on this repo. Configure here.