Repository navigation
Keep PostgreSQL message recovery aligned after parse errors - #118097
Conversation
`Parse` and `Bind` errors could leave bytes from the declared payload in the connection buffer. The recovery loop then treated those bytes as new frontend messages before it reached the real `Sync`. Read both message payloads through an exact-size `LimitReadBuffer` and consume the declared remainder before propagating an exception. Extend the socket and unit coverage with an embedded fake `Sync` frame. Review: #108469 (comment)
|
Workflow [PR], commit [a78879d] Summary: ✅
AI ReviewSummaryThis PR hardens Findings
|
| Metric | Baseline | Current | Δ |
|---|---|---|---|
| Lines | 88.70% | 88.70% | +0.00% |
| Functions | 92.10% | 92.10% | +0.00% |
| Branches | 81.10% | 81.10% | +0.00% |
Changed lines: Changed C/C++ lines covered: 244/246 (99.19%) · Uncovered code
Bound `Describe`, `Execute`, and `Close` payload reads, and reject non-empty `Sync` payloads before they can end extended-query recovery. Review: #118097 (comment) CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118097&sha=6677f29ec0741275a31ff19ae2116bbf5ee1e182&name_0=PR PR: #118097
Parse `Query` within its declared payload and reject non-empty `CopyDone` messages to preserve PostgreSQL frontend framing. Review: #118097 (comment) CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118097&sha=6677f29ec0741275a31ff19ae2116bbf5ee1e182&name_0=PR PR: #118097
Drain and reject trailing bytes after a `PostgreSQL` frontend message parser finishes, preserving framing without accepting oversized messages. Review: #118097 (comment) CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118097&sha=6677f29ec0741275a31ff19ae2116bbf5ee1e182&name_0=PR PR: #118097
|
|
||
| protected: | ||
| template <typename F> | ||
| static void deserializePayload(ReadBuffer & in, std::string_view message_name, F && deserialize_payload) |
There was a problem hiding this comment.
The new exact-size helper closes the recovery hole for Query / extended-protocol messages, but the same framing invariant is still open during authentication. SASLInitialResponse::deserialize (src/Core/PostgreSQLProtocol.h:566) and PasswordMessage::deserialize (src/Core/PostgreSQLProtocol.h:672) still call readNullTerminated on the live socket after reading the length field, without a LimitReadBuffer. A malformed auth frame can therefore still read past its declared payload into the next frontend message or wait indefinitely for a terminator that is not inside the declared frame. I think these two parsers need the same exact-size treatment as the query messages (possibly via an auth-specific helper that also consumes the leading type byte), plus a regression test that the next message stays unread when the auth payload is truncated.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes3 object files changed (+21.69 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units19 translation units recompiled, 66 s compile time in total, 19 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.08 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
…of-cycle-rejection ClickHouse#118097 moved the `ignore_until_sync` reset out of the `Sync` case in `run()` and into `processSyncQuery()`, which conflicted with the `in_extended_query_cycle` reset that sits beside it. Resolution keeps master's removal and the cycle reset, so every cycle-flag assignment stays in `run()`'s switch and clearing `ignore_until_sync` stays where master put it.
ParseandBindrejected negative count fields before consuming the rest of the declared PostgreSQL message payload. The extended-query recovery loop could then interpret residual payload bytes as new frontend frames and react to a fakeSyncbefore the client sent the real protocol-level message.Read both payloads through an exact-size
LimitReadBuffer. If deserialization fails, consume the declared remainder before propagating the exception to the recovery handler. The regression coverage puts a complete-lookingSyncframe after each invalid count, inside the malformed message payload, and verifies that recovery waits for the realSyncand keeps the connection usable.Related: #108469
Changelog category (leave one):
Workflow [PR]
Sync PR [sync-upstream/pr/118097]