Repository navigation
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR properly defers UnboundedSolaceReader resource teardown on close() when checkpoints are still pending, avoids tracking empty checkpoints in pendingCheckpoints, and ensures restored checkpoints are finalized on reader creation in UnboundedSolaceSource. However, there are a couple of lifecycle edge cases around strong references to closed readers and messages read after the last checkpoint that should be addressed.
🔍 General Feedback
ActiveReadersRegistryuses weak values (CacheBuilder.newBuilder().weakValues()), which works while the runner holds the reader, but once the runner drops its reference afterreader.close(), GC can collect the reader before the delayedfinalizeCheckpoint()orcloseTimeoutFutureruns.- If
reader.close()is called afterstart()/advance()without a subsequentgetCheckpointMark(), the session remains open insessionServiceCachefor up to 1 minute instead of closing immediately, preventing prompt redelivery of uncommitted messages.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
| closed.set(true); | ||
| boolean hasPending; | ||
| synchronized (lock) { | ||
| hasPending = !pendingCheckpoints.isEmpty(); |
There was a problem hiding this comment.
🟠 High: ActiveReadersRegistry uses .weakValues(). Once the runner calls reader.close() and drops its strong reference to the UnboundedSolaceReader (e.g., on cache eviction or split), the only remaining strong reference to this is the lambda scheduled in cleanUpThread (closeTimeoutFuture).
If close() is called multiple times, or if GC runs when closeTimeoutFuture is not holding this, or if ActiveReadersRegistry is queried under memory pressure before closeTimeoutFuture is scheduled, the weak reference in ActiveReadersRegistry can be cleared prematurely. Additionally, if receivedMessages is non-empty when close() is called (messages were read via start()/advance() but never checkpointed) and pendingCheckpoints is empty, receivedMessages should be cleared on close().
Ensure receivedMessages.clear() is called on close(), and consider keeping a strong reference in ActiveReadersRegistry (since ActiveReadersRegistry.unregister(readerUuid) is now guaranteed to be called in closeResources() either upon finalization or after ackDeadline).
|
|
||
| synchronized (lock) { | ||
| SortedMap<Long, PendingCheckpoint> toAck = pendingCheckpoints.headMap(checkpointId, true); | ||
| for (PendingCheckpoint cp : toAck.values()) { |
There was a problem hiding this comment.
🟡 Medium: If two threads call finalizeCheckpoint concurrently (for example, UnboundedSolaceSource.createReader finalizing the checkpoint on resume at the same time as the runner's BundleFinalizer callback for the same or an earlier checkpoint), the second thread will see pendingCheckpoints.isEmpty() inside the synchronized (lock) block while the first thread is still executing msg.ackMessage() asynchronously on ackExecutor.
The second thread will immediately enter the finally block with shouldCloseAfterAck == true and call closeResources(), which calls sessionServiceCache.invalidate(readerUuid) (closing the Solace session) while the first thread's ackExecutor tasks are still in flight, causing msg.ackMessage() to fail with IllegalStateException (session closed).
To prevent closing the session while acknowledgements are still in flight, track in-flight ack operations (or only set shouldCloseAfterAck when !messagesToAck.isEmpty() / when the last in-flight finalizeCheckpoint completes).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #41504 +/- ##
=========================================
Coverage 59.38% 59.38%
Complexity 5137 5137
=========================================
Files 1470 1470
Lines 187512 187512
Branches 3819 3819
=========================================
Hits 111351 111351
Misses 72756 72756
Partials 3405 3405 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Assigning reviewers: R: @chamikaramj 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: @chamikaramj |
SolaceIOalready tracks per-reader checkpoints viaActiveReadersRegistryand catches up earlier checkpoints viapendingCheckpoints.headMap(checkpointId, true)(#38603), but two remaining lifecycle gaps (analogous to #40605 and #41013 inJmsIO) remained:UnboundedSolaceReader.close()synchronously invalidatedsessionServiceCache, unregisteredreaderUuidfromActiveReadersRegistry, and shut downackExecutor. AnyfinalizeCheckpoint()callback arriving afterreader.close()(for instance on bundle commit after reader eviction/split) failed to find the reader and left messages unacknowledged.UnboundedSolaceSource.createReader(options, checkpointMark)ignoredcheckpointMark, so recreating a reader from a committed checkpoint in the same JVM without a prior finalize callback did not acknowledge those messages.Changes
sessionServiceCache.invalidate,ActiveReadersRegistry.unregister, andackExecutor.shutdown()inUnboundedSolaceReader.close()until all pending non-empty checkpoints finalize (orackDeadlineexpires, closing immediately once drained).pendingCheckpoints, while still incrementingcheckpointIdso finalizing an empty checkpoint continues to acknowledge earlier pending checkpoints without blockingclose().checkpointMark.finalizeCheckpoint()inUnboundedSolaceSource.createReader()when resuming from a non-null checkpoint.SolaceIOReadTest.testRestoredCheckpointAfterCloseAndResume.