Skip to content

Fix demand handoff in eagerFutureSink - #3823

Draft
He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:fix/eager-future-sink-demand-handoff
Draft

He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:fix/eager-future-sink-demand-handoff

Conversation

@He-Pin

@He-Pin He-Pin commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Motivation

Sink.eagerFutureSink pulls from upstream before the future supplies the inner sink. When the inner sink materializes, the handoff must preserve that outstanding pull and respect the inner sink's demand.

Modification

Reuse the outstanding upstream pull. If an element arrives before the inner sink requests it, keep it buffered. On normal upstream completion, deliver any buffered element on demand before completing. Leave the public API, failure propagation, and cancellation behavior unchanged.

Result

The handoff neither issues a duplicate pull nor drops a buffered final element on normal completion. Three regression tests exercise the real operator: inner demand first, an upstream element first, and upstream completion with an element buffered.

The three new Scala 2.13 regression tests passed before the test-only formatting update. On the current commit, Scalafmt, Code Style, and binary compatibility passed. See Checks for the full CI status.

References

Refs playframework/playframework#13793.

Motivation:
An outstanding eager upstream pull can race with materialization of the selected sink.

Modification:
Reuse the outstanding pull and wait for inner demand before forwarding a buffered element. Keep the final element until it has been delivered before normal completion. Cover both arrival orders and the normal completion boundary with directional tests.

Result:
Eager prefetch is preserved without a duplicate pull, loss of the first element, or a public API change.

Tests:
The preceding revision's functional CI passed. Scoped ScalaFmt 3.11.5 passed for this revision; its sole delta is a whitespace-only test constructor wrap with identical parsed Scala AST.

References:
Refs playframework/playframework#13793.
@He-Pin
He-Pin force-pushed the fix/eager-future-sink-demand-handoff branch from 46e5082 to 43830ac Compare November 29, 2026 06:13
@He-Pin
He-Pin requested review from gmethvin and pjfanning and a balanced review from Copilot and removed request for gmethvin November 29, 2026 06:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants