feat: Add BidirectionalGracefulShutdown CancellationStrategy#3024
Draft
He-Pin wants to merge 1 commit into
Draft
feat: Add BidirectionalGracefulShutdown CancellationStrategy#3024He-Pin wants to merge 1 commit into
He-Pin wants to merge 1 commit into
Conversation
Motivation: Addresses issue #17997 - Clarify stream closing semantics for bidirectional components. When a bidirectional component is about to finish, completing the downstream side (regularly or with an error) can race against cancelling the upstream side. If the cancellation arrives first, the error signal is lost because the connection is already cancelled. Modification: - Added new strategy to - This strategy first completes all output ports, then waits for a grace period to allow the error to propagate through the counterpart, and finally cancels all input ports - Added Java API method - Added comprehensive tests to verify the new behavior - The strategy prevents race conditions in BidiFlow stacks where error propagation is important Result: - Bidirectional components can now gracefully shut down by completing outputs first - Error signals have a chance to propagate through the counterpart before upstream cancellation - Addresses the race condition described in akka/akka-core#17997 Tests: - stream-tests / Test / testOnly org.apache.pekko.stream.scaladsl.CancellationStrategySpec: All 15 tests passed Refs: akka/akka-core#17997
pjfanning
reviewed
May 31, 2026
| * through both inputs and outputs, and error propagation is important for proper diagnostics. | ||
| * | ||
| * @param delay the grace period to wait after completing outputs before cancelling inputs | ||
| */ |
pjfanning
reviewed
May 31, 2026
| * the error has a chance to bubble through the counterpart before the upstream is cancelled. | ||
| * | ||
| * @param delay the grace period to wait after completing outputs before cancelling inputs | ||
| */ |
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.
Motivation
Addresses issue #17997 - Clarify stream closing semantics for bidirectional components.
When a bidirectional component is about to finish, completing the downstream side (regularly or with an error) can race against cancelling the upstream side. If the cancellation arrives first, the error signal is lost because the connection is already cancelled.
Modification
Result
Tests
References