You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "He-Pin (via GitHub)" <gi...@apache.org> on 2026/04/18 23:12:20 UTC

[PR] feat(stream): replace fanout publisher runtime with GraphStage bridge [pekko]

He-Pin opened a new pull request, #2874:
URL: https://github.com/apache/pekko/pull/2874

   ## Summary
   This is the second #2860 slice.
   
   It replaces the actor-backed runtime behind `Sink.asPublisher(fanout = true)` with `FanoutPublisherBridgeStage`, removes the legacy `FanoutProcessor.scala`, replaces the old implementation-bound spec with `FanoutPublisherBehaviorSpec`, and adds the matching `2.0.x` MiMa exclusions.
   
   The runtime stays on a dedicated internal fanout bridge and preserves the existing terminal-signal contract already exercised by `FlowSpec`. This code is part of Apache Pekko, which is now Apache licensed.
   
   ## Motivation
   - remove the remaining legacy actor-backed fanout runtime from the fanout publisher path
   - keep `Sink.asPublisher(fanout = true)` behavior-compatible while moving the runtime to GraphStage-based stream infrastructure
   - replace implementation-bound actor tests with black-box behavior coverage and TCK-backed validation
   
   ## Modification
   - rewire `FanoutPublisherSink.create` in `stream/src/main/scala/org/apache/pekko/stream/impl/Sinks.scala`
   - add `stream/src/main/scala/org/apache/pekko/stream/impl/FanoutPublisherBridgeStage.scala`
   - delete `stream/src/main/scala/org/apache/pekko/stream/impl/FanoutProcessor.scala`
   - replace `stream-tests/src/test/scala/org/apache/pekko/stream/impl/FanoutProcessorSpec.scala` with `stream-tests/src/test/scala/org/apache/pekko/stream/impl/FanoutPublisherBehaviorSpec.scala`
   - add `stream/src/main/mima-filters/2.0.x.backwards.excludes/remove-fanout-processor.excludes`
   
   ## Result
   - the fanout publisher path no longer depends on `FanoutProcessorImpl`
   - timeout, late-subscriber, downstream-failure, and multi-subscriber delivery behavior remain covered
   - the slice is independently reviewable and leaves the TLS migration as the next focused step
   
   ## Validation
   - `sbt scalafmtAll`
   - `sbt "stream/test:compile"`
   - `sbt "stream/mimaReportBinaryIssues"`
   - `sbt "stream-tests/testOnly org.apache.pekko.stream.impl.FanoutPublisherBehaviorSpec org.apache.pekko.stream.impl.TimeoutsSpec org.apache.pekko.stream.scaladsl.FlowSpec org.apache.pekko.stream.scaladsl.SinkSpec"`
   - `sbt "stream-tests/testOnly org.apache.pekko.stream.javadsl.SinkTest"`
   - `sbt "stream-tests-tck/testOnly org.apache.pekko.stream.tck.FanoutPublisherTest"`
   
   ## Upstream / references
   - Issue: https://github.com/apache/pekko/issues/2860
   - Related prior exploration: https://github.com/apache/pekko/pull/1705 and https://github.com/akka/akka-core/issues/21261
   - No single upstream Akka commit maps 1:1 to this bridge; this PR is derived from the current Pekko codebase, issue #2860, and the existing Pekko behavioral contract.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat(stream): replace fanout publisher runtime with GraphStage bridge [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #2874:
URL: https://github.com/apache/pekko/pull/2874#discussion_r3110195886


##########
stream/src/main/scala/org/apache/pekko/stream/impl/FanoutPublisherBridgeStage.scala:
##########
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.stream.impl
+
+import java.util.concurrent.atomic.{ AtomicBoolean, AtomicReference }
+
+import scala.annotation.tailrec
+import scala.collection.immutable
+import scala.util.control.NoStackTrace
+
+import org.apache.pekko
+import pekko.annotation.InternalApi
+import pekko.stream.ActorAttributes.StreamSubscriptionTimeout
+import pekko.stream.Attributes.InputBuffer
+import pekko.stream.StreamSubscriptionTimeoutTerminationMode
+import pekko.stream._
+import pekko.stream.impl.Stages.DefaultAttributes
+import pekko.stream.stage.{
+  AsyncCallback,
+  GraphStageLogic,
+  GraphStageWithMaterializedValue,
+  InHandler,
+  TimerGraphStageLogic
+}
+
+import org.reactivestreams.{ Publisher, Subscriber }
+
+/**
+ * INTERNAL API
+ */
+@InternalApi private[pekko] final class FanoutPublisherBridgeStage[T]
+    extends GraphStageWithMaterializedValue[SinkShape[T], Publisher[T]] {
+  import StreamSubscriptionTimeoutTerminationMode.{ CancelTermination, NoopTermination, WarnTermination }
+
+  private val SubscriptionTimerKey = "FanoutPublisherBridgeStage.subscription-timeout"
+
+  val in: Inlet[T] = Inlet("FanoutPublisherBridgeStage.in")
+  override val shape: SinkShape[T] = SinkShape(in)
+  override protected def initialAttributes: Attributes = DefaultAttributes.fanoutPublisherSink
+
+  override def toString: String = "FanoutPublisherBridgeStage"
+
+  override def createLogicAndMaterializedValue(
+      inheritedAttributes: Attributes): (GraphStageLogic, Publisher[T]) = {
+    object logic extends TimerGraphStageLogic(shape) with InHandler with SubscriberManagement[T] {
+      override type S = FanoutPublisherBridgeSubscription[T]
+
+      private val StreamSubscriptionTimeout(timeout, timeoutMode) =
+        inheritedAttributes.mandatoryAttribute[StreamSubscriptionTimeout]
+
+      override def initialBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].initial
+      override def maxBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].max
+
+      private var everSubscribed = false
+      private var requestedFromUpstream = 0L
+
+      private val requestCallback = getAsyncCallback[(FanoutPublisherBridgeSubscription[T], Long)] {
+        case (subscription, elements) =>
+          moreRequested(subscription, elements)
+          tryPullIfNeeded()
+      }
+
+      private val cancelCallback = getAsyncCallback[FanoutPublisherBridgeSubscription[T]] { subscription =>
+        unregisterSubscription(subscription)
+        tryPullIfNeeded()
+      }
+
+      var materializedPublisher: FanoutPublisherBridgePublisher[T] = null
+
+      private val registerPendingSubscribers = getAsyncCallback[Unit] { _ =>
+        materializedPublisher.takePendingSubscribers().foreach(registerSubscriber)
+        tryPullIfNeeded()
+      }
+
+      materializedPublisher = new FanoutPublisherBridgePublisher[T](registerPendingSubscribers)
+
+      override def preStart(): Unit = {
+        setKeepGoing(true)
+        if (timeoutMode != NoopTermination) scheduleOnce(SubscriptionTimerKey, timeout)
+      }
+
+      override protected def onTimer(timerKey: Any): Unit =
+        if (timerKey == SubscriptionTimerKey && !everSubscribed) {
+          timeoutMode match {
+            case CancelTermination =>
+              val ex = new SubscriptionTimeoutException(
+                s"Subscription timeout expired, no subscriber attached to [$materializedPublisher]") with NoStackTrace
+              materializer.logger.warning(
+                "Subscription timeout expired for [{}], no subscriber attached in time",
+                materializedPublisher)
+              materializedPublisher.shutdown(Some(ex))
+              failStage(ex)
+            case WarnTermination =>
+              materializer.logger.warning("Subscription timeout for {}", this)
+            case NoopTermination => // won't happen
+          }
+        }
+
+      override protected def requestFromUpstream(elements: Long): Unit = {
+        requestedFromUpstream += elements
+        tryPullIfNeeded()
+      }
+
+      override protected def cancelUpstream(): Unit =
+        if (!isClosed(in)) cancel(in)
+
+      override protected def shutdown(completed: Boolean): Unit = {
+        materializedPublisher.shutdown(if (completed) None else ActorPublisher.SomeNormalShutdownReason)
+        completeStage()
+      }
+
+      override protected def createSubscription(subscriber: Subscriber[_ >: T]): S = {
+        everSubscribed = true
+        cancelTimer(SubscriptionTimerKey)
+        new FanoutPublisherBridgeSubscription[T](subscriber, requestCallback, cancelCallback)
+      }
+
+      override def onPush(): Unit = {
+        if (requestedFromUpstream <= 0)
+          throw new IllegalStateException(s"onPush without outstanding upstream demand: $requestedFromUpstream")
+        requestedFromUpstream -= 1
+        pushToDownstream(grab(in))
+        tryPullIfNeeded()
+      }
+
+      override def onUpstreamFinish(): Unit =
+        completeDownstream()
+
+      override def onUpstreamFailure(ex: Throwable): Unit = {
+        abortDownstream(ex)
+        materializedPublisher.shutdown(Some(ex))
+        failStage(ex)
+      }
+
+      override def postStop(): Unit =
+        try abortDownstream(ActorPublisher.NormalShutdownReason)
+        finally materializedPublisher.shutdown(ActorPublisher.SomeNormalShutdownReason)
+
+      private def tryPullIfNeeded(): Unit =
+        if (requestedFromUpstream > 0 && !hasBeenPulled(in) && !isClosed(in)) pull(in)
+
+      setHandler(in, this)
+    }
+
+    (logic, logic.materializedPublisher)
+  }
+}
+
+/**
+ * INTERNAL API
+ */
+@InternalApi private[pekko] final class FanoutPublisherBridgeSubscription[T](
+    override val subscriber: Subscriber[_ >: T],
+    requestCallback: AsyncCallback[(FanoutPublisherBridgeSubscription[T], Long)],
+    cancelCallback: AsyncCallback[FanoutPublisherBridgeSubscription[T]])
+    extends SubscriptionWithCursor[T] {
+
+  override def request(elements: Long): Unit =
+    requestCallback.invoke((this, elements))
+
+  override def cancel(): Unit =
+    cancelCallback.invoke(this)
+}
+
+/**
+ * INTERNAL API
+ */
+@InternalApi private[pekko] final class FanoutPublisherBridgePublisher[T](
+    registerPendingSubscribers: AsyncCallback[Unit])
+    extends Publisher[T] {
+  import ReactiveStreamsCompliance._
+
+  private val pendingSubscribers = new AtomicReference[immutable.Seq[Subscriber[_ >: T]]](Nil)
+  private val shutdownStarted = new AtomicBoolean(false)
+
+  @volatile private var shutdownReason: Option[Throwable] = None
+
+  override def subscribe(subscriber: Subscriber[_ >: T]): Unit = {
+    requireNonNullSubscriber(subscriber)
+
+    @tailrec def doSubscribe(): Unit = {

Review Comment:
   would this be possible to add?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat(stream): replace fanout publisher runtime with GraphStage bridge [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #2874:
URL: https://github.com/apache/pekko/pull/2874#discussion_r3108049757


##########
stream/src/main/scala/org/apache/pekko/stream/impl/Sinks.scala:
##########
@@ -115,11 +115,13 @@ import org.reactivestreams.Subscriber
     extends SinkModule[In, Publisher[In]](shape) {
 
   override def create(context: MaterializationContext): (Subscriber[In], Publisher[In]) = {
-    val impl = context.materializer.actorOf(context, FanoutProcessorImpl.props(context.effectiveAttributes))
-    val fanoutProcessor = new ActorProcessor[In, In](impl)
-    // Resolve cyclic dependency with actor. This MUST be the first message no matter what.
-    impl ! ExposedPublisher(fanoutProcessor.asInstanceOf[ActorPublisher[Any]])
-    (fanoutProcessor, fanoutProcessor)
+    context.materializer.materialize(

Review Comment:
   Correctness concern: The new \`Sinks.scala\` implementation materializes \`Source.asSubscriber[In].toMat(Sink.fromGraph(new FanoutPublisherBridgeStage[In]))(Keep.both)\`. This creates a nested materialization. The \`context.effectiveAttributes\` is passed to the inner materialize call, but verify that attributes like \`ActorAttributes.streamSubscriptionTimeout\` and \`Attributes.InputBuffer\` are correctly propagated through the nested materialization boundary. The old implementation read attributes directly from \`context.effectiveAttributes\` in \`FanoutProcessorImpl.props\`. If attributes are not properly inherited in the nested graph, the timeout and buffer settings could be ignored.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat(stream): replace fanout publisher runtime with GraphStage bridge [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #2874:
URL: https://github.com/apache/pekko/pull/2874#discussion_r3108048366


##########
stream/src/main/scala/org/apache/pekko/stream/impl/FanoutPublisherBridgeStage.scala:
##########
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.stream.impl
+
+import java.util.concurrent.atomic.{ AtomicBoolean, AtomicReference }
+
+import scala.annotation.tailrec
+import scala.collection.immutable
+import scala.util.control.NoStackTrace
+
+import org.apache.pekko
+import pekko.annotation.InternalApi
+import pekko.stream.ActorAttributes.StreamSubscriptionTimeout
+import pekko.stream.Attributes.InputBuffer
+import pekko.stream.StreamSubscriptionTimeoutTerminationMode
+import pekko.stream._
+import pekko.stream.impl.Stages.DefaultAttributes
+import pekko.stream.stage.{
+  AsyncCallback,
+  GraphStageLogic,
+  GraphStageWithMaterializedValue,
+  InHandler,
+  TimerGraphStageLogic
+}
+
+import org.reactivestreams.{ Publisher, Subscriber }
+
+/**
+ * INTERNAL API
+ */
+@InternalApi private[pekko] final class FanoutPublisherBridgeStage[T]
+    extends GraphStageWithMaterializedValue[SinkShape[T], Publisher[T]] {
+  import StreamSubscriptionTimeoutTerminationMode.{ CancelTermination, NoopTermination, WarnTermination }
+
+  private val SubscriptionTimerKey = "FanoutPublisherBridgeStage.subscription-timeout"
+
+  val in: Inlet[T] = Inlet("FanoutPublisherBridgeStage.in")
+  override val shape: SinkShape[T] = SinkShape(in)
+  override protected def initialAttributes: Attributes = DefaultAttributes.fanoutPublisherSink
+
+  override def toString: String = "FanoutPublisherBridgeStage"
+
+  override def createLogicAndMaterializedValue(
+      inheritedAttributes: Attributes): (GraphStageLogic, Publisher[T]) = {
+    object logic extends TimerGraphStageLogic(shape) with InHandler with SubscriberManagement[T] {
+      override type S = FanoutPublisherBridgeSubscription[T]
+
+      private val StreamSubscriptionTimeout(timeout, timeoutMode) =
+        inheritedAttributes.mandatoryAttribute[StreamSubscriptionTimeout]
+
+      override def initialBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].initial
+      override def maxBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].max
+
+      private var everSubscribed = false
+      private var requestedFromUpstream = 0L
+
+      private val requestCallback = getAsyncCallback[(FanoutPublisherBridgeSubscription[T], Long)] {
+        case (subscription, elements) =>
+          moreRequested(subscription, elements)
+          tryPullIfNeeded()
+      }
+
+      private val cancelCallback = getAsyncCallback[FanoutPublisherBridgeSubscription[T]] { subscription =>
+        unregisterSubscription(subscription)
+        tryPullIfNeeded()
+      }
+
+      var materializedPublisher: FanoutPublisherBridgePublisher[T] = null
+
+      private val registerPendingSubscribers = getAsyncCallback[Unit] { _ =>
+        materializedPublisher.takePendingSubscribers().foreach(registerSubscriber)
+        tryPullIfNeeded()
+      }
+
+      materializedPublisher = new FanoutPublisherBridgePublisher[T](registerPendingSubscribers)
+
+      override def preStart(): Unit = {
+        setKeepGoing(true)
+        if (timeoutMode != NoopTermination) scheduleOnce(SubscriptionTimerKey, timeout)
+      }
+
+      override protected def onTimer(timerKey: Any): Unit =
+        if (timerKey == SubscriptionTimerKey && !everSubscribed) {
+          timeoutMode match {
+            case CancelTermination =>
+              val ex = new SubscriptionTimeoutException(
+                s"Subscription timeout expired, no subscriber attached to [$materializedPublisher]") with NoStackTrace
+              materializer.logger.warning(
+                "Subscription timeout expired for [{}], no subscriber attached in time",
+                materializedPublisher)
+              materializedPublisher.shutdown(Some(ex))
+              failStage(ex)
+            case WarnTermination =>
+              materializer.logger.warning("Subscription timeout for {}", this)
+            case NoopTermination => // won't happen
+          }
+        }
+
+      override protected def requestFromUpstream(elements: Long): Unit = {
+        requestedFromUpstream += elements
+        tryPullIfNeeded()
+      }
+
+      override protected def cancelUpstream(): Unit =
+        if (!isClosed(in)) cancel(in)
+
+      override protected def shutdown(completed: Boolean): Unit = {
+        materializedPublisher.shutdown(if (completed) None else ActorPublisher.SomeNormalShutdownReason)
+        completeStage()
+      }
+
+      override protected def createSubscription(subscriber: Subscriber[_ >: T]): S = {
+        everSubscribed = true
+        cancelTimer(SubscriptionTimerKey)
+        new FanoutPublisherBridgeSubscription[T](subscriber, requestCallback, cancelCallback)
+      }
+
+      override def onPush(): Unit = {
+        if (requestedFromUpstream <= 0)
+          throw new IllegalStateException(s"onPush without outstanding upstream demand: $requestedFromUpstream")
+        requestedFromUpstream -= 1
+        pushToDownstream(grab(in))
+        tryPullIfNeeded()
+      }
+
+      override def onUpstreamFinish(): Unit =
+        completeDownstream()
+
+      override def onUpstreamFailure(ex: Throwable): Unit = {
+        abortDownstream(ex)
+        materializedPublisher.shutdown(Some(ex))
+        failStage(ex)
+      }
+
+      override def postStop(): Unit =
+        try abortDownstream(ActorPublisher.NormalShutdownReason)
+        finally materializedPublisher.shutdown(ActorPublisher.SomeNormalShutdownReason)
+
+      private def tryPullIfNeeded(): Unit =
+        if (requestedFromUpstream > 0 && !hasBeenPulled(in) && !isClosed(in)) pull(in)
+
+      setHandler(in, this)
+    }

Review Comment:
   Potential memory leak / GC issue: \`postStop\` calls \`abortDownstream\` followed by \`shutdown\`. If \`abortDownstream\` throws (e.g., from subscriber \`tryOnError\` violations), the \`finally\` block still runs \`shutdown\`, but \`abortDownstream\` has already set \`endOfStream = ErrorCompleted\` and cleared \`subscriptions\`. The subsequent \`shutdown\` call on the \`materializedPublisher\` is correct, but consider whether the \`try/finally\` should also guard against exceptions from \`abortDownstream\` to ensure clean state. The old \`FanoutProcessorImpl\` did not have this pattern - verify this is intentional and safe.



##########
stream/src/main/scala/org/apache/pekko/stream/impl/FanoutPublisherBridgeStage.scala:
##########
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.stream.impl
+
+import java.util.concurrent.atomic.{ AtomicBoolean, AtomicReference }
+
+import scala.annotation.tailrec
+import scala.collection.immutable
+import scala.util.control.NoStackTrace
+
+import org.apache.pekko
+import pekko.annotation.InternalApi
+import pekko.stream.ActorAttributes.StreamSubscriptionTimeout
+import pekko.stream.Attributes.InputBuffer
+import pekko.stream.StreamSubscriptionTimeoutTerminationMode
+import pekko.stream._
+import pekko.stream.impl.Stages.DefaultAttributes
+import pekko.stream.stage.{
+  AsyncCallback,
+  GraphStageLogic,
+  GraphStageWithMaterializedValue,
+  InHandler,
+  TimerGraphStageLogic
+}
+
+import org.reactivestreams.{ Publisher, Subscriber }
+
+/**
+ * INTERNAL API
+ */
+@InternalApi private[pekko] final class FanoutPublisherBridgeStage[T]
+    extends GraphStageWithMaterializedValue[SinkShape[T], Publisher[T]] {
+  import StreamSubscriptionTimeoutTerminationMode.{ CancelTermination, NoopTermination, WarnTermination }
+
+  private val SubscriptionTimerKey = "FanoutPublisherBridgeStage.subscription-timeout"
+
+  val in: Inlet[T] = Inlet("FanoutPublisherBridgeStage.in")
+  override val shape: SinkShape[T] = SinkShape(in)
+  override protected def initialAttributes: Attributes = DefaultAttributes.fanoutPublisherSink
+
+  override def toString: String = "FanoutPublisherBridgeStage"
+
+  override def createLogicAndMaterializedValue(
+      inheritedAttributes: Attributes): (GraphStageLogic, Publisher[T]) = {
+    object logic extends TimerGraphStageLogic(shape) with InHandler with SubscriberManagement[T] {
+      override type S = FanoutPublisherBridgeSubscription[T]
+
+      private val StreamSubscriptionTimeout(timeout, timeoutMode) =
+        inheritedAttributes.mandatoryAttribute[StreamSubscriptionTimeout]
+
+      override def initialBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].initial
+      override def maxBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].max
+
+      private var everSubscribed = false
+      private var requestedFromUpstream = 0L
+
+      private val requestCallback = getAsyncCallback[(FanoutPublisherBridgeSubscription[T], Long)] {
+        case (subscription, elements) =>
+          moreRequested(subscription, elements)
+          tryPullIfNeeded()
+      }
+
+      private val cancelCallback = getAsyncCallback[FanoutPublisherBridgeSubscription[T]] { subscription =>
+        unregisterSubscription(subscription)
+        tryPullIfNeeded()
+      }
+
+      var materializedPublisher: FanoutPublisherBridgePublisher[T] = null
+
+      private val registerPendingSubscribers = getAsyncCallback[Unit] { _ =>
+        materializedPublisher.takePendingSubscribers().foreach(registerSubscriber)
+        tryPullIfNeeded()
+      }
+
+      materializedPublisher = new FanoutPublisherBridgePublisher[T](registerPendingSubscribers)
+
+      override def preStart(): Unit = {
+        setKeepGoing(true)
+        if (timeoutMode != NoopTermination) scheduleOnce(SubscriptionTimerKey, timeout)
+      }
+
+      override protected def onTimer(timerKey: Any): Unit =
+        if (timerKey == SubscriptionTimerKey && !everSubscribed) {
+          timeoutMode match {
+            case CancelTermination =>
+              val ex = new SubscriptionTimeoutException(
+                s"Subscription timeout expired, no subscriber attached to [$materializedPublisher]") with NoStackTrace
+              materializer.logger.warning(
+                "Subscription timeout expired for [{}], no subscriber attached in time",
+                materializedPublisher)
+              materializedPublisher.shutdown(Some(ex))
+              failStage(ex)
+            case WarnTermination =>
+              materializer.logger.warning("Subscription timeout for {}", this)
+            case NoopTermination => // won't happen
+          }
+        }
+
+      override protected def requestFromUpstream(elements: Long): Unit = {
+        requestedFromUpstream += elements
+        tryPullIfNeeded()
+      }
+
+      override protected def cancelUpstream(): Unit =
+        if (!isClosed(in)) cancel(in)
+
+      override protected def shutdown(completed: Boolean): Unit = {
+        materializedPublisher.shutdown(if (completed) None else ActorPublisher.SomeNormalShutdownReason)
+        completeStage()
+      }
+
+      override protected def createSubscription(subscriber: Subscriber[_ >: T]): S = {
+        everSubscribed = true
+        cancelTimer(SubscriptionTimerKey)
+        new FanoutPublisherBridgeSubscription[T](subscriber, requestCallback, cancelCallback)
+      }
+
+      override def onPush(): Unit = {
+        if (requestedFromUpstream <= 0)
+          throw new IllegalStateException(s"onPush without outstanding upstream demand: $requestedFromUpstream")
+        requestedFromUpstream -= 1
+        pushToDownstream(grab(in))
+        tryPullIfNeeded()
+      }
+
+      override def onUpstreamFinish(): Unit =
+        completeDownstream()
+
+      override def onUpstreamFailure(ex: Throwable): Unit = {
+        abortDownstream(ex)
+        materializedPublisher.shutdown(Some(ex))
+        failStage(ex)
+      }
+
+      override def postStop(): Unit =
+        try abortDownstream(ActorPublisher.NormalShutdownReason)
+        finally materializedPublisher.shutdown(ActorPublisher.SomeNormalShutdownReason)
+
+      private def tryPullIfNeeded(): Unit =
+        if (requestedFromUpstream > 0 && !hasBeenPulled(in) && !isClosed(in)) pull(in)
+
+      setHandler(in, this)
+    }
+
+    (logic, logic.materializedPublisher)
+  }
+}
+
+/**
+ * INTERNAL API
+ */
+@InternalApi private[pekko] final class FanoutPublisherBridgeSubscription[T](
+    override val subscriber: Subscriber[_ >: T],
+    requestCallback: AsyncCallback[(FanoutPublisherBridgeSubscription[T], Long)],
+    cancelCallback: AsyncCallback[FanoutPublisherBridgeSubscription[T]])
+    extends SubscriptionWithCursor[T] {
+
+  override def request(elements: Long): Unit =
+    requestCallback.invoke((this, elements))
+
+  override def cancel(): Unit =
+    cancelCallback.invoke(this)
+}
+
+/**
+ * INTERNAL API
+ */
+@InternalApi private[pekko] final class FanoutPublisherBridgePublisher[T](
+    registerPendingSubscribers: AsyncCallback[Unit])
+    extends Publisher[T] {
+  import ReactiveStreamsCompliance._
+
+  private val pendingSubscribers = new AtomicReference[immutable.Seq[Subscriber[_ >: T]]](Nil)
+  private val shutdownStarted = new AtomicBoolean(false)
+
+  @volatile private var shutdownReason: Option[Throwable] = None
+
+  override def subscribe(subscriber: Subscriber[_ >: T]): Unit = {
+    requireNonNullSubscriber(subscriber)
+
+    @tailrec def doSubscribe(): Unit = {

Review Comment:
   Long-term safety risk: \`FanoutPublisherBridgePublisher\` holds a reference to \`registerPendingSubscribers: AsyncCallback[Unit]\`, which internally holds a reference to the \`GraphStageLogic\`. If the \`Publisher\` is retained by user code after the stage terminates, this creates a reference chain that prevents GC of the entire stage logic and all its state (buffer, subscriptions, callbacks). Consider using a weak reference pattern or clearing the callback reference in \`shutdown()\` to break this chain for long-running applications.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat(stream): replace fanout publisher runtime with GraphStage bridge [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #2874:
URL: https://github.com/apache/pekko/pull/2874#discussion_r3108049036


##########
stream/src/main/scala/org/apache/pekko/stream/impl/FanoutPublisherBridgeStage.scala:
##########
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.stream.impl
+
+import java.util.concurrent.atomic.{ AtomicBoolean, AtomicReference }
+
+import scala.annotation.tailrec
+import scala.collection.immutable
+import scala.util.control.NoStackTrace
+
+import org.apache.pekko
+import pekko.annotation.InternalApi
+import pekko.stream.ActorAttributes.StreamSubscriptionTimeout
+import pekko.stream.Attributes.InputBuffer
+import pekko.stream.StreamSubscriptionTimeoutTerminationMode
+import pekko.stream._
+import pekko.stream.impl.Stages.DefaultAttributes
+import pekko.stream.stage.{
+  AsyncCallback,
+  GraphStageLogic,
+  GraphStageWithMaterializedValue,
+  InHandler,
+  TimerGraphStageLogic
+}
+
+import org.reactivestreams.{ Publisher, Subscriber }
+
+/**
+ * INTERNAL API
+ */
+@InternalApi private[pekko] final class FanoutPublisherBridgeStage[T]
+    extends GraphStageWithMaterializedValue[SinkShape[T], Publisher[T]] {
+  import StreamSubscriptionTimeoutTerminationMode.{ CancelTermination, NoopTermination, WarnTermination }
+
+  private val SubscriptionTimerKey = "FanoutPublisherBridgeStage.subscription-timeout"
+
+  val in: Inlet[T] = Inlet("FanoutPublisherBridgeStage.in")
+  override val shape: SinkShape[T] = SinkShape(in)
+  override protected def initialAttributes: Attributes = DefaultAttributes.fanoutPublisherSink
+
+  override def toString: String = "FanoutPublisherBridgeStage"
+
+  override def createLogicAndMaterializedValue(
+      inheritedAttributes: Attributes): (GraphStageLogic, Publisher[T]) = {
+    object logic extends TimerGraphStageLogic(shape) with InHandler with SubscriberManagement[T] {
+      override type S = FanoutPublisherBridgeSubscription[T]
+
+      private val StreamSubscriptionTimeout(timeout, timeoutMode) =
+        inheritedAttributes.mandatoryAttribute[StreamSubscriptionTimeout]
+
+      override def initialBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].initial
+      override def maxBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].max
+
+      private var everSubscribed = false
+      private var requestedFromUpstream = 0L
+
+      private val requestCallback = getAsyncCallback[(FanoutPublisherBridgeSubscription[T], Long)] {
+        case (subscription, elements) =>
+          moreRequested(subscription, elements)
+          tryPullIfNeeded()
+      }
+
+      private val cancelCallback = getAsyncCallback[FanoutPublisherBridgeSubscription[T]] { subscription =>
+        unregisterSubscription(subscription)
+        tryPullIfNeeded()
+      }
+
+      var materializedPublisher: FanoutPublisherBridgePublisher[T] = null
+
+      private val registerPendingSubscribers = getAsyncCallback[Unit] { _ =>
+        materializedPublisher.takePendingSubscribers().foreach(registerSubscriber)
+        tryPullIfNeeded()
+      }
+
+      materializedPublisher = new FanoutPublisherBridgePublisher[T](registerPendingSubscribers)
+
+      override def preStart(): Unit = {
+        setKeepGoing(true)
+        if (timeoutMode != NoopTermination) scheduleOnce(SubscriptionTimerKey, timeout)
+      }
+
+      override protected def onTimer(timerKey: Any): Unit =
+        if (timerKey == SubscriptionTimerKey && !everSubscribed) {
+          timeoutMode match {
+            case CancelTermination =>
+              val ex = new SubscriptionTimeoutException(
+                s"Subscription timeout expired, no subscriber attached to [$materializedPublisher]") with NoStackTrace
+              materializer.logger.warning(
+                "Subscription timeout expired for [{}], no subscriber attached in time",
+                materializedPublisher)
+              materializedPublisher.shutdown(Some(ex))
+              failStage(ex)
+            case WarnTermination =>
+              materializer.logger.warning("Subscription timeout for {}", this)
+            case NoopTermination => // won't happen
+          }
+        }
+
+      override protected def requestFromUpstream(elements: Long): Unit = {
+        requestedFromUpstream += elements
+        tryPullIfNeeded()
+      }

Review Comment:
   Correctness issue: In \`onTimer\` for \`WarnTermination\`, only a warning is logged but the stage continues running. However, unlike \`CancelTermination\`, this does NOT call \`failStage\` or terminate. If no subscriber ever connects, the stage will keep running indefinitely with \`setKeepGoing(true)\`, potentially holding upstream resources (e.g., a connection or actor) forever. The old \`FanoutProcessorImpl\` had the same behavior, but since we are refactoring, consider whether \`WarnTermination\` should also trigger some form of cleanup after the warning, or at minimum document this expected behavior.



##########
stream/src/main/scala/org/apache/pekko/stream/impl/FanoutPublisherBridgeStage.scala:
##########
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.stream.impl
+
+import java.util.concurrent.atomic.{ AtomicBoolean, AtomicReference }
+
+import scala.annotation.tailrec
+import scala.collection.immutable
+import scala.util.control.NoStackTrace
+
+import org.apache.pekko
+import pekko.annotation.InternalApi
+import pekko.stream.ActorAttributes.StreamSubscriptionTimeout
+import pekko.stream.Attributes.InputBuffer
+import pekko.stream.StreamSubscriptionTimeoutTerminationMode
+import pekko.stream._
+import pekko.stream.impl.Stages.DefaultAttributes
+import pekko.stream.stage.{
+  AsyncCallback,
+  GraphStageLogic,
+  GraphStageWithMaterializedValue,
+  InHandler,
+  TimerGraphStageLogic
+}
+
+import org.reactivestreams.{ Publisher, Subscriber }
+
+/**
+ * INTERNAL API
+ */
+@InternalApi private[pekko] final class FanoutPublisherBridgeStage[T]
+    extends GraphStageWithMaterializedValue[SinkShape[T], Publisher[T]] {
+  import StreamSubscriptionTimeoutTerminationMode.{ CancelTermination, NoopTermination, WarnTermination }
+
+  private val SubscriptionTimerKey = "FanoutPublisherBridgeStage.subscription-timeout"
+
+  val in: Inlet[T] = Inlet("FanoutPublisherBridgeStage.in")
+  override val shape: SinkShape[T] = SinkShape(in)
+  override protected def initialAttributes: Attributes = DefaultAttributes.fanoutPublisherSink
+
+  override def toString: String = "FanoutPublisherBridgeStage"
+
+  override def createLogicAndMaterializedValue(
+      inheritedAttributes: Attributes): (GraphStageLogic, Publisher[T]) = {
+    object logic extends TimerGraphStageLogic(shape) with InHandler with SubscriberManagement[T] {
+      override type S = FanoutPublisherBridgeSubscription[T]
+
+      private val StreamSubscriptionTimeout(timeout, timeoutMode) =
+        inheritedAttributes.mandatoryAttribute[StreamSubscriptionTimeout]
+
+      override def initialBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].initial
+      override def maxBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].max
+
+      private var everSubscribed = false
+      private var requestedFromUpstream = 0L
+
+      private val requestCallback = getAsyncCallback[(FanoutPublisherBridgeSubscription[T], Long)] {
+        case (subscription, elements) =>
+          moreRequested(subscription, elements)
+          tryPullIfNeeded()
+      }
+
+      private val cancelCallback = getAsyncCallback[FanoutPublisherBridgeSubscription[T]] { subscription =>
+        unregisterSubscription(subscription)
+        tryPullIfNeeded()
+      }
+
+      var materializedPublisher: FanoutPublisherBridgePublisher[T] = null
+
+      private val registerPendingSubscribers = getAsyncCallback[Unit] { _ =>
+        materializedPublisher.takePendingSubscribers().foreach(registerSubscriber)
+        tryPullIfNeeded()
+      }
+
+      materializedPublisher = new FanoutPublisherBridgePublisher[T](registerPendingSubscribers)
+
+      override def preStart(): Unit = {
+        setKeepGoing(true)
+        if (timeoutMode != NoopTermination) scheduleOnce(SubscriptionTimerKey, timeout)
+      }
+
+      override protected def onTimer(timerKey: Any): Unit =
+        if (timerKey == SubscriptionTimerKey && !everSubscribed) {
+          timeoutMode match {
+            case CancelTermination =>
+              val ex = new SubscriptionTimeoutException(
+                s"Subscription timeout expired, no subscriber attached to [$materializedPublisher]") with NoStackTrace
+              materializer.logger.warning(
+                "Subscription timeout expired for [{}], no subscriber attached in time",
+                materializedPublisher)
+              materializedPublisher.shutdown(Some(ex))
+              failStage(ex)
+            case WarnTermination =>
+              materializer.logger.warning("Subscription timeout for {}", this)
+            case NoopTermination => // won't happen
+          }
+        }
+
+      override protected def requestFromUpstream(elements: Long): Unit = {
+        requestedFromUpstream += elements
+        tryPullIfNeeded()
+      }
+
+      override protected def cancelUpstream(): Unit =
+        if (!isClosed(in)) cancel(in)
+
+      override protected def shutdown(completed: Boolean): Unit = {
+        materializedPublisher.shutdown(if (completed) None else ActorPublisher.SomeNormalShutdownReason)
+        completeStage()
+      }
+
+      override protected def createSubscription(subscriber: Subscriber[_ >: T]): S = {
+        everSubscribed = true
+        cancelTimer(SubscriptionTimerKey)
+        new FanoutPublisherBridgeSubscription[T](subscriber, requestCallback, cancelCallback)
+      }
+
+      override def onPush(): Unit = {
+        if (requestedFromUpstream <= 0)
+          throw new IllegalStateException(s"onPush without outstanding upstream demand: $requestedFromUpstream")
+        requestedFromUpstream -= 1
+        pushToDownstream(grab(in))

Review Comment:
   Race condition risk: \`everSubscribed\` is a plain \`var\` checked in \`onTimer\` (timer thread callback) and set in \`createSubscription\` (called from \`registerSubscriber\` which runs on the stage interpreter thread). Since \`TimerGraphStageLogic\` timers fire on the same interpreter thread, this is technically single-threaded. However, \`createSubscription\` is called from \`registerSubscriber\` in \`SubscriberManagement\`, which can be invoked via the \`registerPendingSubscribers\` async callback. Verify that the async callback execution model guarantees that \`everSubscribed\` visibility is safe. Consider using \`@volatile\` or documenting the thread-safety assumption.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat(stream): replace fanout publisher runtime with GraphStage bridge [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #2874:
URL: https://github.com/apache/pekko/pull/2874#discussion_r3108048366


##########
stream/src/main/scala/org/apache/pekko/stream/impl/FanoutPublisherBridgeStage.scala:
##########
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.stream.impl
+
+import java.util.concurrent.atomic.{ AtomicBoolean, AtomicReference }
+
+import scala.annotation.tailrec
+import scala.collection.immutable
+import scala.util.control.NoStackTrace
+
+import org.apache.pekko
+import pekko.annotation.InternalApi
+import pekko.stream.ActorAttributes.StreamSubscriptionTimeout
+import pekko.stream.Attributes.InputBuffer
+import pekko.stream.StreamSubscriptionTimeoutTerminationMode
+import pekko.stream._
+import pekko.stream.impl.Stages.DefaultAttributes
+import pekko.stream.stage.{
+  AsyncCallback,
+  GraphStageLogic,
+  GraphStageWithMaterializedValue,
+  InHandler,
+  TimerGraphStageLogic
+}
+
+import org.reactivestreams.{ Publisher, Subscriber }
+
+/**
+ * INTERNAL API
+ */
+@InternalApi private[pekko] final class FanoutPublisherBridgeStage[T]
+    extends GraphStageWithMaterializedValue[SinkShape[T], Publisher[T]] {
+  import StreamSubscriptionTimeoutTerminationMode.{ CancelTermination, NoopTermination, WarnTermination }
+
+  private val SubscriptionTimerKey = "FanoutPublisherBridgeStage.subscription-timeout"
+
+  val in: Inlet[T] = Inlet("FanoutPublisherBridgeStage.in")
+  override val shape: SinkShape[T] = SinkShape(in)
+  override protected def initialAttributes: Attributes = DefaultAttributes.fanoutPublisherSink
+
+  override def toString: String = "FanoutPublisherBridgeStage"
+
+  override def createLogicAndMaterializedValue(
+      inheritedAttributes: Attributes): (GraphStageLogic, Publisher[T]) = {
+    object logic extends TimerGraphStageLogic(shape) with InHandler with SubscriberManagement[T] {
+      override type S = FanoutPublisherBridgeSubscription[T]
+
+      private val StreamSubscriptionTimeout(timeout, timeoutMode) =
+        inheritedAttributes.mandatoryAttribute[StreamSubscriptionTimeout]
+
+      override def initialBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].initial
+      override def maxBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].max
+
+      private var everSubscribed = false
+      private var requestedFromUpstream = 0L
+
+      private val requestCallback = getAsyncCallback[(FanoutPublisherBridgeSubscription[T], Long)] {
+        case (subscription, elements) =>
+          moreRequested(subscription, elements)
+          tryPullIfNeeded()
+      }
+
+      private val cancelCallback = getAsyncCallback[FanoutPublisherBridgeSubscription[T]] { subscription =>
+        unregisterSubscription(subscription)
+        tryPullIfNeeded()
+      }
+
+      var materializedPublisher: FanoutPublisherBridgePublisher[T] = null
+
+      private val registerPendingSubscribers = getAsyncCallback[Unit] { _ =>
+        materializedPublisher.takePendingSubscribers().foreach(registerSubscriber)
+        tryPullIfNeeded()
+      }
+
+      materializedPublisher = new FanoutPublisherBridgePublisher[T](registerPendingSubscribers)
+
+      override def preStart(): Unit = {
+        setKeepGoing(true)
+        if (timeoutMode != NoopTermination) scheduleOnce(SubscriptionTimerKey, timeout)
+      }
+
+      override protected def onTimer(timerKey: Any): Unit =
+        if (timerKey == SubscriptionTimerKey && !everSubscribed) {
+          timeoutMode match {
+            case CancelTermination =>
+              val ex = new SubscriptionTimeoutException(
+                s"Subscription timeout expired, no subscriber attached to [$materializedPublisher]") with NoStackTrace
+              materializer.logger.warning(
+                "Subscription timeout expired for [{}], no subscriber attached in time",
+                materializedPublisher)
+              materializedPublisher.shutdown(Some(ex))
+              failStage(ex)
+            case WarnTermination =>
+              materializer.logger.warning("Subscription timeout for {}", this)
+            case NoopTermination => // won't happen
+          }
+        }
+
+      override protected def requestFromUpstream(elements: Long): Unit = {
+        requestedFromUpstream += elements
+        tryPullIfNeeded()
+      }
+
+      override protected def cancelUpstream(): Unit =
+        if (!isClosed(in)) cancel(in)
+
+      override protected def shutdown(completed: Boolean): Unit = {
+        materializedPublisher.shutdown(if (completed) None else ActorPublisher.SomeNormalShutdownReason)
+        completeStage()
+      }
+
+      override protected def createSubscription(subscriber: Subscriber[_ >: T]): S = {
+        everSubscribed = true
+        cancelTimer(SubscriptionTimerKey)
+        new FanoutPublisherBridgeSubscription[T](subscriber, requestCallback, cancelCallback)
+      }
+
+      override def onPush(): Unit = {
+        if (requestedFromUpstream <= 0)
+          throw new IllegalStateException(s"onPush without outstanding upstream demand: $requestedFromUpstream")
+        requestedFromUpstream -= 1
+        pushToDownstream(grab(in))
+        tryPullIfNeeded()
+      }
+
+      override def onUpstreamFinish(): Unit =
+        completeDownstream()
+
+      override def onUpstreamFailure(ex: Throwable): Unit = {
+        abortDownstream(ex)
+        materializedPublisher.shutdown(Some(ex))
+        failStage(ex)
+      }
+
+      override def postStop(): Unit =
+        try abortDownstream(ActorPublisher.NormalShutdownReason)
+        finally materializedPublisher.shutdown(ActorPublisher.SomeNormalShutdownReason)
+
+      private def tryPullIfNeeded(): Unit =
+        if (requestedFromUpstream > 0 && !hasBeenPulled(in) && !isClosed(in)) pull(in)
+
+      setHandler(in, this)
+    }

Review Comment:
   Potential memory leak / GC issue: \`postStop\` calls \`abortDownstream\` followed by \`shutdown\`. If \`abortDownstream\` throws (e.g., from subscriber \`tryOnError\` violations), the \`finally\` block still runs \`shutdown\`, but \`abortDownstream\` has already set \`endOfStream = ErrorCompleted\` and cleared \`subscriptions\`. The subsequent \`shutdown\` call on the \`materializedPublisher\` is correct, but consider whether the \`try/finally\` should also guard against exceptions from \`abortDownstream\` to ensure clean state. The old \`FanoutProcessorImpl\` did not have this pattern - verify this is intentional and safe.



##########
stream/src/main/scala/org/apache/pekko/stream/impl/FanoutPublisherBridgeStage.scala:
##########
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.stream.impl
+
+import java.util.concurrent.atomic.{ AtomicBoolean, AtomicReference }
+
+import scala.annotation.tailrec
+import scala.collection.immutable
+import scala.util.control.NoStackTrace
+
+import org.apache.pekko
+import pekko.annotation.InternalApi
+import pekko.stream.ActorAttributes.StreamSubscriptionTimeout
+import pekko.stream.Attributes.InputBuffer
+import pekko.stream.StreamSubscriptionTimeoutTerminationMode
+import pekko.stream._
+import pekko.stream.impl.Stages.DefaultAttributes
+import pekko.stream.stage.{
+  AsyncCallback,
+  GraphStageLogic,
+  GraphStageWithMaterializedValue,
+  InHandler,
+  TimerGraphStageLogic
+}
+
+import org.reactivestreams.{ Publisher, Subscriber }
+
+/**
+ * INTERNAL API
+ */
+@InternalApi private[pekko] final class FanoutPublisherBridgeStage[T]
+    extends GraphStageWithMaterializedValue[SinkShape[T], Publisher[T]] {
+  import StreamSubscriptionTimeoutTerminationMode.{ CancelTermination, NoopTermination, WarnTermination }
+
+  private val SubscriptionTimerKey = "FanoutPublisherBridgeStage.subscription-timeout"
+
+  val in: Inlet[T] = Inlet("FanoutPublisherBridgeStage.in")
+  override val shape: SinkShape[T] = SinkShape(in)
+  override protected def initialAttributes: Attributes = DefaultAttributes.fanoutPublisherSink
+
+  override def toString: String = "FanoutPublisherBridgeStage"
+
+  override def createLogicAndMaterializedValue(
+      inheritedAttributes: Attributes): (GraphStageLogic, Publisher[T]) = {
+    object logic extends TimerGraphStageLogic(shape) with InHandler with SubscriberManagement[T] {
+      override type S = FanoutPublisherBridgeSubscription[T]
+
+      private val StreamSubscriptionTimeout(timeout, timeoutMode) =
+        inheritedAttributes.mandatoryAttribute[StreamSubscriptionTimeout]
+
+      override def initialBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].initial
+      override def maxBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].max
+
+      private var everSubscribed = false
+      private var requestedFromUpstream = 0L
+
+      private val requestCallback = getAsyncCallback[(FanoutPublisherBridgeSubscription[T], Long)] {
+        case (subscription, elements) =>
+          moreRequested(subscription, elements)
+          tryPullIfNeeded()
+      }
+
+      private val cancelCallback = getAsyncCallback[FanoutPublisherBridgeSubscription[T]] { subscription =>
+        unregisterSubscription(subscription)
+        tryPullIfNeeded()
+      }
+
+      var materializedPublisher: FanoutPublisherBridgePublisher[T] = null
+
+      private val registerPendingSubscribers = getAsyncCallback[Unit] { _ =>
+        materializedPublisher.takePendingSubscribers().foreach(registerSubscriber)
+        tryPullIfNeeded()
+      }
+
+      materializedPublisher = new FanoutPublisherBridgePublisher[T](registerPendingSubscribers)
+
+      override def preStart(): Unit = {
+        setKeepGoing(true)
+        if (timeoutMode != NoopTermination) scheduleOnce(SubscriptionTimerKey, timeout)
+      }
+
+      override protected def onTimer(timerKey: Any): Unit =
+        if (timerKey == SubscriptionTimerKey && !everSubscribed) {
+          timeoutMode match {
+            case CancelTermination =>
+              val ex = new SubscriptionTimeoutException(
+                s"Subscription timeout expired, no subscriber attached to [$materializedPublisher]") with NoStackTrace
+              materializer.logger.warning(
+                "Subscription timeout expired for [{}], no subscriber attached in time",
+                materializedPublisher)
+              materializedPublisher.shutdown(Some(ex))
+              failStage(ex)
+            case WarnTermination =>
+              materializer.logger.warning("Subscription timeout for {}", this)
+            case NoopTermination => // won't happen
+          }
+        }
+
+      override protected def requestFromUpstream(elements: Long): Unit = {
+        requestedFromUpstream += elements
+        tryPullIfNeeded()
+      }

Review Comment:
   Correctness issue: In \`onTimer\` for \`WarnTermination\`, only a warning is logged but the stage continues running. However, unlike \`CancelTermination\`, this does NOT call \`failStage\` or terminate. If no subscriber ever connects, the stage will keep running indefinitely with \`setKeepGoing(true)\`, potentially holding upstream resources (e.g., a connection or actor) forever. The old \`FanoutProcessorImpl\` had the same behavior, but since we are refactoring, consider whether \`WarnTermination\` should also trigger some form of cleanup after the warning, or at minimum document this expected behavior.



##########
stream/src/main/scala/org/apache/pekko/stream/impl/FanoutPublisherBridgeStage.scala:
##########
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.stream.impl
+
+import java.util.concurrent.atomic.{ AtomicBoolean, AtomicReference }
+
+import scala.annotation.tailrec
+import scala.collection.immutable
+import scala.util.control.NoStackTrace
+
+import org.apache.pekko
+import pekko.annotation.InternalApi
+import pekko.stream.ActorAttributes.StreamSubscriptionTimeout
+import pekko.stream.Attributes.InputBuffer
+import pekko.stream.StreamSubscriptionTimeoutTerminationMode
+import pekko.stream._
+import pekko.stream.impl.Stages.DefaultAttributes
+import pekko.stream.stage.{
+  AsyncCallback,
+  GraphStageLogic,
+  GraphStageWithMaterializedValue,
+  InHandler,
+  TimerGraphStageLogic
+}
+
+import org.reactivestreams.{ Publisher, Subscriber }
+
+/**
+ * INTERNAL API
+ */
+@InternalApi private[pekko] final class FanoutPublisherBridgeStage[T]
+    extends GraphStageWithMaterializedValue[SinkShape[T], Publisher[T]] {
+  import StreamSubscriptionTimeoutTerminationMode.{ CancelTermination, NoopTermination, WarnTermination }
+
+  private val SubscriptionTimerKey = "FanoutPublisherBridgeStage.subscription-timeout"
+
+  val in: Inlet[T] = Inlet("FanoutPublisherBridgeStage.in")
+  override val shape: SinkShape[T] = SinkShape(in)
+  override protected def initialAttributes: Attributes = DefaultAttributes.fanoutPublisherSink
+
+  override def toString: String = "FanoutPublisherBridgeStage"
+
+  override def createLogicAndMaterializedValue(
+      inheritedAttributes: Attributes): (GraphStageLogic, Publisher[T]) = {
+    object logic extends TimerGraphStageLogic(shape) with InHandler with SubscriberManagement[T] {
+      override type S = FanoutPublisherBridgeSubscription[T]
+
+      private val StreamSubscriptionTimeout(timeout, timeoutMode) =
+        inheritedAttributes.mandatoryAttribute[StreamSubscriptionTimeout]
+
+      override def initialBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].initial
+      override def maxBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].max
+
+      private var everSubscribed = false
+      private var requestedFromUpstream = 0L
+
+      private val requestCallback = getAsyncCallback[(FanoutPublisherBridgeSubscription[T], Long)] {
+        case (subscription, elements) =>
+          moreRequested(subscription, elements)
+          tryPullIfNeeded()
+      }
+
+      private val cancelCallback = getAsyncCallback[FanoutPublisherBridgeSubscription[T]] { subscription =>
+        unregisterSubscription(subscription)
+        tryPullIfNeeded()
+      }
+
+      var materializedPublisher: FanoutPublisherBridgePublisher[T] = null
+
+      private val registerPendingSubscribers = getAsyncCallback[Unit] { _ =>
+        materializedPublisher.takePendingSubscribers().foreach(registerSubscriber)
+        tryPullIfNeeded()
+      }
+
+      materializedPublisher = new FanoutPublisherBridgePublisher[T](registerPendingSubscribers)
+
+      override def preStart(): Unit = {
+        setKeepGoing(true)
+        if (timeoutMode != NoopTermination) scheduleOnce(SubscriptionTimerKey, timeout)
+      }
+
+      override protected def onTimer(timerKey: Any): Unit =
+        if (timerKey == SubscriptionTimerKey && !everSubscribed) {
+          timeoutMode match {
+            case CancelTermination =>
+              val ex = new SubscriptionTimeoutException(
+                s"Subscription timeout expired, no subscriber attached to [$materializedPublisher]") with NoStackTrace
+              materializer.logger.warning(
+                "Subscription timeout expired for [{}], no subscriber attached in time",
+                materializedPublisher)
+              materializedPublisher.shutdown(Some(ex))
+              failStage(ex)
+            case WarnTermination =>
+              materializer.logger.warning("Subscription timeout for {}", this)
+            case NoopTermination => // won't happen
+          }
+        }
+
+      override protected def requestFromUpstream(elements: Long): Unit = {
+        requestedFromUpstream += elements
+        tryPullIfNeeded()
+      }
+
+      override protected def cancelUpstream(): Unit =
+        if (!isClosed(in)) cancel(in)
+
+      override protected def shutdown(completed: Boolean): Unit = {
+        materializedPublisher.shutdown(if (completed) None else ActorPublisher.SomeNormalShutdownReason)
+        completeStage()
+      }
+
+      override protected def createSubscription(subscriber: Subscriber[_ >: T]): S = {
+        everSubscribed = true
+        cancelTimer(SubscriptionTimerKey)
+        new FanoutPublisherBridgeSubscription[T](subscriber, requestCallback, cancelCallback)
+      }
+
+      override def onPush(): Unit = {
+        if (requestedFromUpstream <= 0)
+          throw new IllegalStateException(s"onPush without outstanding upstream demand: $requestedFromUpstream")
+        requestedFromUpstream -= 1
+        pushToDownstream(grab(in))

Review Comment:
   Race condition risk: \`everSubscribed\` is a plain \`var\` checked in \`onTimer\` (timer thread callback) and set in \`createSubscription\` (called from \`registerSubscriber\` which runs on the stage interpreter thread). Since \`TimerGraphStageLogic\` timers fire on the same interpreter thread, this is technically single-threaded. However, \`createSubscription\` is called from \`registerSubscriber\` in \`SubscriberManagement\`, which can be invoked via the \`registerPendingSubscribers\` async callback. Verify that the async callback execution model guarantees that \`everSubscribed\` visibility is safe. Consider using \`@volatile\` or documenting the thread-safety assumption.



##########
stream/src/main/scala/org/apache/pekko/stream/impl/Sinks.scala:
##########
@@ -115,11 +115,13 @@ import org.reactivestreams.Subscriber
     extends SinkModule[In, Publisher[In]](shape) {
 
   override def create(context: MaterializationContext): (Subscriber[In], Publisher[In]) = {
-    val impl = context.materializer.actorOf(context, FanoutProcessorImpl.props(context.effectiveAttributes))
-    val fanoutProcessor = new ActorProcessor[In, In](impl)
-    // Resolve cyclic dependency with actor. This MUST be the first message no matter what.
-    impl ! ExposedPublisher(fanoutProcessor.asInstanceOf[ActorPublisher[Any]])
-    (fanoutProcessor, fanoutProcessor)
+    context.materializer.materialize(

Review Comment:
   Correctness concern: The new \`Sinks.scala\` implementation materializes \`Source.asSubscriber[In].toMat(Sink.fromGraph(new FanoutPublisherBridgeStage[In]))(Keep.both)\`. This creates a nested materialization. The \`context.effectiveAttributes\` is passed to the inner materialize call, but verify that attributes like \`ActorAttributes.streamSubscriptionTimeout\` and \`Attributes.InputBuffer\` are correctly propagated through the nested materialization boundary. The old implementation read attributes directly from \`context.effectiveAttributes\` in \`FanoutProcessorImpl.props\`. If attributes are not properly inherited in the nested graph, the timeout and buffer settings could be ignored.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat(stream): replace fanout publisher runtime with GraphStage bridge [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #2874:
URL: https://github.com/apache/pekko/pull/2874#discussion_r3110685785


##########
stream/src/main/scala/org/apache/pekko/stream/impl/FanoutPublisherBridgeStage.scala:
##########
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.stream.impl
+
+import java.util.concurrent.atomic.{ AtomicBoolean, AtomicReference }
+
+import scala.annotation.tailrec
+import scala.collection.immutable
+import scala.util.control.NoStackTrace
+
+import org.apache.pekko
+import pekko.annotation.InternalApi
+import pekko.stream.ActorAttributes.StreamSubscriptionTimeout
+import pekko.stream.Attributes.InputBuffer
+import pekko.stream.StreamSubscriptionTimeoutTerminationMode
+import pekko.stream._
+import pekko.stream.impl.Stages.DefaultAttributes
+import pekko.stream.stage.{
+  AsyncCallback,
+  GraphStageLogic,
+  GraphStageWithMaterializedValue,
+  InHandler,
+  TimerGraphStageLogic
+}
+
+import org.reactivestreams.{ Publisher, Subscriber }
+
+/**
+ * INTERNAL API
+ */
+@InternalApi private[pekko] final class FanoutPublisherBridgeStage[T]
+    extends GraphStageWithMaterializedValue[SinkShape[T], Publisher[T]] {
+  import StreamSubscriptionTimeoutTerminationMode.{ CancelTermination, NoopTermination, WarnTermination }
+
+  private val SubscriptionTimerKey = "FanoutPublisherBridgeStage.subscription-timeout"
+
+  val in: Inlet[T] = Inlet("FanoutPublisherBridgeStage.in")
+  override val shape: SinkShape[T] = SinkShape(in)
+  override protected def initialAttributes: Attributes = DefaultAttributes.fanoutPublisherSink
+
+  override def toString: String = "FanoutPublisherBridgeStage"
+
+  override def createLogicAndMaterializedValue(
+      inheritedAttributes: Attributes): (GraphStageLogic, Publisher[T]) = {
+    object logic extends TimerGraphStageLogic(shape) with InHandler with SubscriberManagement[T] {
+      override type S = FanoutPublisherBridgeSubscription[T]
+
+      private val StreamSubscriptionTimeout(timeout, timeoutMode) =
+        inheritedAttributes.mandatoryAttribute[StreamSubscriptionTimeout]
+
+      override def initialBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].initial
+      override def maxBufferSize: Int = inheritedAttributes.mandatoryAttribute[InputBuffer].max
+
+      private var everSubscribed = false
+      private var requestedFromUpstream = 0L
+
+      private val requestCallback = getAsyncCallback[(FanoutPublisherBridgeSubscription[T], Long)] {
+        case (subscription, elements) =>
+          moreRequested(subscription, elements)
+          tryPullIfNeeded()
+      }
+
+      private val cancelCallback = getAsyncCallback[FanoutPublisherBridgeSubscription[T]] { subscription =>
+        unregisterSubscription(subscription)
+        tryPullIfNeeded()
+      }
+
+      var materializedPublisher: FanoutPublisherBridgePublisher[T] = null
+
+      private val registerPendingSubscribers = getAsyncCallback[Unit] { _ =>
+        materializedPublisher.takePendingSubscribers().foreach(registerSubscriber)
+        tryPullIfNeeded()
+      }
+
+      materializedPublisher = new FanoutPublisherBridgePublisher[T](registerPendingSubscribers)
+
+      override def preStart(): Unit = {
+        setKeepGoing(true)
+        if (timeoutMode != NoopTermination) scheduleOnce(SubscriptionTimerKey, timeout)
+      }
+
+      override protected def onTimer(timerKey: Any): Unit =
+        if (timerKey == SubscriptionTimerKey && !everSubscribed) {
+          timeoutMode match {
+            case CancelTermination =>
+              val ex = new SubscriptionTimeoutException(
+                s"Subscription timeout expired, no subscriber attached to [$materializedPublisher]") with NoStackTrace
+              materializer.logger.warning(
+                "Subscription timeout expired for [{}], no subscriber attached in time",
+                materializedPublisher)
+              materializedPublisher.shutdown(Some(ex))
+              failStage(ex)
+            case WarnTermination =>
+              materializer.logger.warning("Subscription timeout for {}", this)
+            case NoopTermination => // won't happen
+          }
+        }
+
+      override protected def requestFromUpstream(elements: Long): Unit = {
+        requestedFromUpstream += elements
+        tryPullIfNeeded()
+      }
+
+      override protected def cancelUpstream(): Unit =
+        if (!isClosed(in)) cancel(in)
+
+      override protected def shutdown(completed: Boolean): Unit = {
+        materializedPublisher.shutdown(if (completed) None else ActorPublisher.SomeNormalShutdownReason)
+        completeStage()
+      }
+
+      override protected def createSubscription(subscriber: Subscriber[_ >: T]): S = {
+        everSubscribed = true
+        cancelTimer(SubscriptionTimerKey)
+        new FanoutPublisherBridgeSubscription[T](subscriber, requestCallback, cancelCallback)
+      }
+
+      override def onPush(): Unit = {
+        if (requestedFromUpstream <= 0)
+          throw new IllegalStateException(s"onPush without outstanding upstream demand: $requestedFromUpstream")
+        requestedFromUpstream -= 1
+        pushToDownstream(grab(in))
+        tryPullIfNeeded()
+      }
+
+      override def onUpstreamFinish(): Unit =
+        completeDownstream()
+
+      override def onUpstreamFailure(ex: Throwable): Unit = {
+        abortDownstream(ex)
+        materializedPublisher.shutdown(Some(ex))
+        failStage(ex)
+      }
+
+      override def postStop(): Unit =
+        try abortDownstream(ActorPublisher.NormalShutdownReason)
+        finally materializedPublisher.shutdown(ActorPublisher.SomeNormalShutdownReason)
+
+      private def tryPullIfNeeded(): Unit =
+        if (requestedFromUpstream > 0 && !hasBeenPulled(in) && !isClosed(in)) pull(in)
+
+      setHandler(in, this)
+    }
+
+    (logic, logic.materializedPublisher)
+  }
+}
+
+/**
+ * INTERNAL API
+ */
+@InternalApi private[pekko] final class FanoutPublisherBridgeSubscription[T](
+    override val subscriber: Subscriber[_ >: T],
+    requestCallback: AsyncCallback[(FanoutPublisherBridgeSubscription[T], Long)],
+    cancelCallback: AsyncCallback[FanoutPublisherBridgeSubscription[T]])
+    extends SubscriptionWithCursor[T] {
+
+  override def request(elements: Long): Unit =
+    requestCallback.invoke((this, elements))
+
+  override def cancel(): Unit =
+    cancelCallback.invoke(this)
+}
+
+/**
+ * INTERNAL API
+ */
+@InternalApi private[pekko] final class FanoutPublisherBridgePublisher[T](
+    registerPendingSubscribers: AsyncCallback[Unit])
+    extends Publisher[T] {
+  import ReactiveStreamsCompliance._
+
+  private val pendingSubscribers = new AtomicReference[immutable.Seq[Subscriber[_ >: T]]](Nil)
+  private val shutdownStarted = new AtomicBoolean(false)
+
+  @volatile private var shutdownReason: Option[Throwable] = None
+
+  override def subscribe(subscriber: Subscriber[_ >: T]): Unit = {
+    requireNonNullSubscriber(subscriber)
+
+    @tailrec def doSubscribe(): Unit = {

Review Comment:
   I think there is no need to fix this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat(stream): replace fanout publisher runtime with GraphStage bridge [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin merged PR #2874:
URL: https://github.com/apache/pekko/pull/2874


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org