fix(stream): notify PartitionHub consumers on materializer shutdown#3347
Open
He-Pin wants to merge 3 commits into
Open
fix(stream): notify PartitionHub consumers on materializer shutdown#3347He-Pin wants to merge 3 commits into
He-Pin wants to merge 3 commits into
Conversation
Motivation: When the materializer running a PartitionHub.sink is shut down (e.g. the hosting actor stops), consumers materialized on a different materializer may not be notified of the hub's termination. This mirrors the same bug in BroadcastHub (see #3345). Modification: Move registered-consumer notification from onUpstreamFailure to postStop so postStop is the single notification point. postStop now handles both Open (normal termination) and Closed (after upstream failure) states, ensuring registered consumers always receive the appropriate signal. 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 References: Refs #3345
Motivation: If one consumer's callback throws during hub shutdown, the remaining consumers must still be notified. Modification: Wrap each callback.invoke in onUpstreamFailure and postStop with try/catch NonFatal so a single consumer failure does not short-circuit the notification loop. Result: All reachable consumers are notified even when one consumer's callback throws. Tests: - sbt "stream-tests / Test / testOnly org.apache.pekko.stream.scaladsl.HubSpec" 51 passed, 0 failed References: Refs #3345
Motivation: The Closed(_) branch comment in postStop said "fall through to notify registered below" but the code directly calls notifyRegisteredConsumers() rather than falling through, making the comment misleading. Modification: Reword the comment to accurately describe the direct call. Result: Comment now matches the actual control flow in postStop. Tests: - sbt "stream-tests / Test / testOnly org.apache.pekko.stream.scaladsl.HubSpec" — all 51 tests passed References: Refs #3345
8ed3677 to
9ad7de6
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