fix: restore per-element demand replenishment across async boundary - #3461
Draft
He-Pin wants to merge 2 commits into
Draft
fix: restore per-element demand replenishment across async boundary#3461He-Pin wants to merge 2 commits into
He-Pin wants to merge 2 commits into
Conversation
Motivation: PR apache#3288 batched elements at the async output boundary and flushed them when the interpreter parked. This deferred the demand round-trip to once per flush cycle instead of per element, silently breaking external-source stages (e.g. pekko-connectors UDP) that drop elements when isAvailable(out) is false. See apache#3459. Modification: Revert the output-side batching: send each element directly to the BoundarySubscriber via next() during onPush(), restoring the pre-M4 timing where demand is replenished after every element. Remove the now-unused enqueueBatchElement/flushBatch/clearBatch/flushOutputs machinery. Result: Demand across an internal async boundary is again replenished per element, fixing silent datagram loss in the UDP connector and any other stage that treats "no demand right now" as a signal to drop. Tests: - sbt "stream-tests / Test / testOnly org.apache.pekko.stream.FusingSpec" -- 19/19 passed - sbt "stream-tests / Test / testOnly org.apache.pekko.stream.scaladsl.PublisherSinkSpec org.apache.pekko.stream.io.FileSinkSpec org.apache.pekko.stream.scaladsl.FlowMapWithResourceSpec org.apache.pekko.stream.scaladsl.FlowSpec" -- 78/78 passed - sbt "stream / mimaReportBinaryIssues" -- passed References: Fixes apache#3459
He-Pin
marked this pull request as draft
August 24, 2026 03:59
…e#3459) Motivation: External-source stages (e.g. UDP connector) that push via async callback and check isAvailable(out) before pushing need per-element demand replenishment across async boundaries. Without a directional test, this behavior can silently regress again. Modification: Add a FusingSpec test that creates a GraphStageWithMaterializedValue exposing an AsyncCallback, offers 100 elements rapidly across an async boundary, and asserts zero drops. Result: The UDP connector failure pattern from apache#3459 is now covered by a directional regression test in pekko core. Tests: - sbt "stream-tests / Test / testOnly org.apache.pekko.stream.FusingSpec" -- 20/20 passed References: Refs apache#3459
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
PR #3288 batched elements at the async output boundary and flushed them when the interpreter parked. This deferred the demand round-trip to once per flush cycle (~16 elements) instead of per element, silently breaking external-source stages that drop elements when
isAvailable(out)is false. Thepekko-connectorsUDP connector loses ~15/16 datagrams on M4.Fixes #3459
Modification
Revert the output-side batching: send each element directly to the
BoundarySubscribervianext()duringonPush(), restoring the pre-M4 timing where demand is replenished after every element. Remove the now-unusedenqueueBatchElement/flushBatch/clearBatch/flushOutputsmachinery.The
BoundarySubscribertrait,OnNextBatchevent class, and input-sidereceiveNextBatchare retained as internal API surface (no behavioral change on the input side).Result
Demand across an internal async boundary is again replenished per element, fixing silent datagram loss in the UDP connector and any other stage that treats "no demand right now" as a signal to drop.
Tests
sbt "stream-tests / Test / testOnly org.apache.pekko.stream.FusingSpec"-- 19/19 passedsbt "stream-tests / Test / testOnly org.apache.pekko.stream.scaladsl.PublisherSinkSpec org.apache.pekko.stream.io.FileSinkSpec org.apache.pekko.stream.scaladsl.FlowMapWithResourceSpec org.apache.pekko.stream.scaladsl.FlowSpec"-- 78/78 passedsbt "stream / mimaReportBinaryIssues"-- passedReferences
Fixes #3459