Repository navigation
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR updates AmqpIO to isolate per-checkpoint tracker snapshots and maintain a weak-valued registry of pending checkpoints per reader, mirroring the checkpoint finalization fixes from JmsIO (#40605, #41013). This ensures restored checkpoints and resumed readers properly acknowledge in-flight trackers and earlier unfinalized checkpoints, while deferring messenger.stop() on reader close until active checkpoints drain.
🔍 General Feedback
- The checkpoint registry, sequence-based catch-up finalization, and backward-compatible
serialVersionUIDpinning are cleanly designed. - One synchronization issue was identified in
AmqpCheckpointMark.acknowledge()/abandonPendingCheckpointsAndStopMessenger():messenger.accept(...)can race withmessenger.stop()when the close timeout expires concurrently withfinalizeCheckpoint(), which is unsafe because Qpid Proton'sMessengerImplis not thread-safe.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
| acknowledge(); | ||
| } | ||
|
|
||
| private synchronized void acknowledge() { |
There was a problem hiding this comment.
🟠 High: acknowledge() can run concurrently with abandonPendingCheckpointsAndStopMessenger() (when the close timeout task fires at the same time finalizeCheckpoint() is executing on another thread). Because pending.removeUpTo(sequence) removes the checkpoint from PendingCheckpoints before calling checkpoint.acknowledge(), a concurrent checkpointPreparer.abandonPendingCheckpoints() call in abandonPendingCheckpointsAndStopMessenger() will not see that checkpoint or acquire its monitor, and will immediately proceed to call messenger.stop() while acknowledge() is calling messenger.accept(tracker, 0). Qpid Proton's Messenger (MessengerImpl) is not thread-safe, so concurrent accept and stop calls can corrupt internal state or throw.
Consider guarding messenger.accept(...) and messenger.stop() with a shared lock (e.g., closeLock or synchronizing on the Messenger instance) and checking that the reader/messenger has not already been stopped before calling accept.
|
Assigning reviewers: R: @kennknowles for label java. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
|
Reminder, please take a look at this pr: @kennknowles |
Similar to the recent JmsIO fixes (#40605, #41013),
AmqpCheckpointMarkpreviously kepttransient Messenger messengerandtransient List<Tracker> trackers, andUnboundedAmqpReaderreused a single mutableAmqpCheckpointMarkacross allgetCheckpointMark()calls:SerializableCoder,readObjectresetstrackersto an empty list and leavesmessengernull, sofinalizeCheckpoint()on a restored mark silently acknowledges nothing.createReader(..., checkpointMark)resume, andUnboundedAmqpReader.close()immediately stopsmessengerbefore in-flight checkpoints finalize.Changes
AmqpCheckpointMark.Preparerand register them in a per-reader weak-valuedPendingCheckpointsregistry (readerId+ monotonicsequenceonAmqpCheckpointMark, withserialVersionUIDpinned for backward compatibility).finalizeCheckpoint()resolves the live reader'sPendingCheckpoints(even from a restored copy) and acknowledges this checkpoint together with all earlier unfinalized checkpoints of the same reader in order.UnboundedAmqpSource.createReader(options, checkpointMark)finalizes the checkpoint it resumes from when its originating reader lives in this JVM.UnboundedAmqpReader.close()waits for in-flight checkpoints to finalize (up to a 60s timeout, closing immediately once drained) before stoppingmessenger.AmqpIOTest.testRestoredCheckpointAcknowledgesLiveTrackersAndEarlierCheckpoints.