Skip to content

fix(stream): notify PartitionHub consumers on materializer shutdown#3347

Merged
He-Pin merged 1 commit into
mainfrom
fix/partition-hub-poststop
Jul 15, 2026
Merged

fix(stream): notify PartitionHub consumers on materializer shutdown#3347
He-Pin merged 1 commit into
mainfrom
fix/partition-hub-poststop

Conversation

@He-Pin

@He-Pin He-Pin commented Jul 14, 2026

Copy link
Copy Markdown
Member

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.

Before: onUpstreamFailure notified registered consumers directly, but postStop did not. This left a gap where consumers could miss notification during materializer shutdown.

After: postStop is the sole notification point for registered consumers, using the failure reason from the Closed state 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
  • Added new test: "notify consumers when hub materializer is shut down" (PartitionHub section)

References

Refs #3345

@He-Pin He-Pin added this to the 2.0.0-M4 milestone Jul 14, 2026
@He-Pin He-Pin added the t:stream Pekko Streams label Jul 14, 2026
@He-Pin He-Pin force-pushed the fix/partition-hub-poststop branch from 8ed3677 to 9ad7de6 Compare July 14, 2026 11:30
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
@He-Pin He-Pin force-pushed the fix/partition-hub-poststop branch from 9ad7de6 to 081f120 Compare July 15, 2026 11:38
@He-Pin He-Pin requested a review from pjfanning July 15, 2026 11:39

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@He-Pin He-Pin merged commit b3c7c24 into main Jul 15, 2026
10 checks passed
@He-Pin He-Pin deleted the fix/partition-hub-poststop branch July 15, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t:stream Pekko Streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants