Skip to content

Correctly flag BufferedPersistentStreamSegment#isClosed - #511

Merged
smcvb merged 1 commit into
mainfrom
bug/persistent-stream-lets-consumers-skip-events-on-termination
Aug 25, 2026
Merged

Correctly flag BufferedPersistentStreamSegment#isClosed#511
smcvb merged 1 commit into
mainfrom
bug/persistent-stream-lets-consumers-skip-events-on-termination

Conversation

@smcvb

@smcvb smcvb commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

This PR corrects the isClosed behavior of theBufferedPersistentStreamSegment.
To that end, we firstly should rely on the FlowControlledBuffer#isClosed() instead of having a custom implementation in the BufferedPersistentStreamSegment.
Remove this ensure the BufferedPersistentStreamSegment does not eagerly report it's closed even though there are still some events buffered in it, as that violates the described contract of the ResultStream.

Furthermore, we should use the closed AtomicBoolean for both BufferedPersistentStreamSegment#close and BufferedPersistentStreamSegment#onCompleted in a compare-and-set (false to true) check.
This ensure we only enqueue the terminal message of the BufferedPersistentStreamSegment once, guarded by the aforementioned AtomicBoolean closed.

Fixing the above allows consumers (e.g., Axon Framework) to base themselves on isClosed per JavaDoc description, ensuring a user does not accidentally skips buffered events.

We should correctly flag a BufferedPersistentStreamSegment as closed.
Firstly, we should rely on the FlowControlledBuffer#isClosed() instead
of having a custom implementation. Furthermore, we should use the closed
 AtomicBoolean for both close() and onCompleted() in a CaS false-true
 style. Correcting this functionality allows consumers to base
 themselves
  on isClosed per JavaDoc description, ensuring a user does not
  accidentally skips queued events.
@sonarqubecloud

Copy link
Copy Markdown

@smcvb
smcvb merged commit c502370 into main Aug 25, 2026
5 checks passed
@smcvb
smcvb deleted the bug/persistent-stream-lets-consumers-skip-events-on-termination branch August 25, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants