Repository navigation
Conversation
apply_replay_head/tail (the exception-replay queue) was only ever cleared in handle_commit(). The one-time 'S' STARTUP message sent at connection setup flows through the exact same queue_append path as transactional messages, so it became the head of that list the instant it was received -- before any transaction had even begun. If the very first transaction a freshly-connected worker processes hits an exception requiring replay, apply_replay_queue_start_replay() points apply_replay_next at apply_replay_head, which was still that stale STARTUP entry, not the transaction's own BEGIN. Replaying it hit a second, compounding issue: the generic per-message pre-processing decides whether to consume an 8-byte remote_insert_lsn field based on the currently negotiated protocol version. The STARTUP message's wire format deliberately never includes that field, since version negotiation hasn't happened yet when it's first sent/parsed. By the time the stale entry gets replayed, the version has already been negotiated to 5 (STARTUP's own job), so the check wrongly fires and consumes 8 bytes that aren't there, shifting every subsequent read 8 bytes into the STARTUP message's own parameter text. "max_proto_version" is always the first parameter sent, so the misaligned read lands on the same character every time, producing the always-identical "unknown action of type o" crash. Root-caused with a temporary shared-memory ring buffer that captured raw wire bytes at both ingestion (PQgetCopyData) and replay (apply_replay_queue_next_entry) time, tagged with a correlating sequence id -- the entry returned at crash time was byte-for-byte identical to this worker's own STARTUP message from earlier in the same connection, not corrupted data. Fix: a deferred-reset flag, set at the end of handle_startup() once negotiation completes, consumed in the main loop right after replication_handler() returns and any need_free bookkeeping for that message is done -- never inside handle_startup() itself, since resetting there would free the entry's buffer while the caller's msg/entry still alias it for the rest of that loop iteration. Verified against a 100%-reliable repro (isolate a subscriber, delete a row locally, run a large single-statement UPDATE on the provider that touches that row, re-enable the subscription so the first transaction it replays after reconnecting requires exception replay): crashed 3/3 times before this fix, passed 2/2 times after, including one run against a fully clean production build with no debug instrumentation. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019z2vqY5jJj13hY87Wq9JrE (cherry picked from commit 26077da) (cherry picked from commit edef36d)
Contributor
Up to standards ✅🟢 Issues
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the "unknown action of type" apply crash reported in #610.
apply_replay_head/apply_replay_tail(the exception-replay queue) were only cleared inhandle_commit(). The one-time'S'STARTUP message sent at connection setup goes through the samequeue_appendpath as transactional messages, so it became the head of the list before any transaction had begun.If the first transaction a freshly connected worker processes hits an exception that needs replay,
apply_replay_queue_start_replay()pointsapply_replay_nextatapply_replay_head. That was still the stale STARTUP entry rather than the transaction's own BEGIN, so replay dispatched on a message type it does not handle and the worker crashed.The change clears the stale STARTUP entry from the replay queue so replay starts at the transaction's BEGIN.
Testing
🤖 Generated with Claude Code
https://claude.ai/code/session_01Meb83hmmxffhEKhUbTkXgi