Skip to content

Fix MapAsyncPartitioned demand-resume deadlock#3365

Merged
He-Pin merged 1 commit into
apache:mainfrom
He-Pin:fix/2886-map-async-partitioned-deadlock
Jul 18, 2026
Merged

Fix MapAsyncPartitioned demand-resume deadlock#3365
He-Pin merged 1 commit into
apache:mainfrom
He-Pin:fix/2886-map-async-partitioned-deadlock

Conversation

@He-Pin

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

Copy link
Copy Markdown
Member

Motivation

Completed mapAsyncPartitioned results can remain buffered until downstream demand resumes. The partitionsInProgress empty shortcut bypasses the push logic, so a completed buffer can stop making progress.

Modification

Remove the partitionsInProgress.isEmpty short-circuit from both ordered and unordered push paths so buffered results are always examined when demand is available.

Add focused backpressure tests for ordered and unordered variants. The tests fill parallelism, consume one result, complete the remaining futures without demand, then verify all buffered results are emitted once demand resumes.

Result

Completed buffered elements are emitted after downstream demand resumes. Ordering and per-partition parallelism semantics are unchanged.

References

Fixes #2886

Motivation:
Completed mapAsyncPartitioned results can remain buffered until downstream demand resumes. The partitionsInProgress empty shortcut bypassed emission and could leave the stage unable to make progress.

Modification:
Always evaluate buffered completed elements in the ordered and unordered push paths. Add focused backpressure tests for both variants.

Result:
Completed elements are emitted when downstream demand resumes without changing ordering or partition-parallelism semantics.

Tests:
- stream-typed-tests MapAsyncPartitionedSpec: 5 repeated runs, 110/110 passed
- stream-tests FlowMapAsyncPartitionedSpec: 24/24 passed
- scalafmt diff mode and list check: passed
- headerCreateAll, checkCodeStyle, and +headerCheckAll: passed
- validatePullRequest: relevant stream batches passed; overall failed on unrelated macOS ARM64/JDK 25 environment tests documented in the PR
- git diff --check: passed
- Qoder stdout review: No must-fix findings

References:
Fixes apache#2886
@He-Pin He-Pin added bug Something isn't working t:stream Pekko Streams labels Jul 18, 2026
@He-Pin He-Pin added this to the 2.0.0-M4 milestone Jul 18, 2026

@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 efc254b into apache:main Jul 18, 2026
10 checks passed
@He-Pin
He-Pin deleted the fix/2886-map-async-partitioned-deadlock branch July 18, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working t:stream Pekko Streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

should process elements in parallel preserving order in partition

2 participants