fix(stream): notify PartitionHub consumers on materializer shutdown#3347
Merged
Conversation
8ed3677 to
9ad7de6
Compare
Motivation: When the materializer running a PartitionHub.sink is shut down (e.g. the hosting actor stops or crashes), consumers materialized on a different materializer may not be notified of the hub's termination. This mirrors the same bug pattern found in BroadcastHub (see #3345). Modification: Move registered-consumer notification from onUpstreamFailure to postStop so that postStop is the single notification point for all consumers. postStop now handles both Open (normal termination) and Closed (after upstream failure) states, ensuring registered consumers always receive the appropriate signal. Each callback invocation is wrapped in try/catch NonFatal so a single consumer failure does not short-circuit the notification loop. Result: PartitionHub consumers are reliably notified when the hub's materializer shuts down, preventing consumers from hanging indefinitely. Tests: - sbt "stream-tests / Test / testOnly org.apache.pekko.stream.scaladsl.HubSpec" References: Refs #3345
9ad7de6 to
081f120
Compare
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
When the materializer running a
PartitionHub.sinkis shut down (e.g. the hosting actor stops or crashes), consumers materialized on a different materializer may not be notified of the hub's termination. This mirrors the same bug pattern found inBroadcastHub(see #3345).Modification
onUpstreamFailuretopostStopso thatpostStopis the single notification point for all consumers.postStopnow handles bothOpen(normal termination) andClosed(after upstream failure) states, ensuring registered consumers always receive the appropriate signal.Before:
onUpstreamFailurenotified registered consumers directly, butpostStopdid not. This left a gap where consumers could miss notification during materializer shutdown.After:
postStopis the sole notification point for registered consumers, using the failure reason from theClosedstate when applicable.Result
PartitionHub consumers are reliably notified when the hub's materializer shuts down, preventing consumers from hanging indefinitely.
Tests
sbt "stream-tests / Test / testOnly org.apache.pekko.stream.scaladsl.HubSpec"— 51 passed, 0 failed"notify consumers when hub materializer is shut down"(PartitionHub section)References
Refs #3345