Skip to content

Fix double close in unfoldResource#3172

Merged
He-Pin merged 1 commit into
apache:mainfrom
He-Pin:issue-3162-unfold-resource-close
Jun 25, 2026
Merged

Fix double close in unfoldResource#3172
He-Pin merged 1 commit into
apache:mainfrom
He-Pin:issue-3162-unfold-resource-close

Conversation

@He-Pin

@He-Pin He-Pin commented Jun 24, 2026

Copy link
Copy Markdown
Member

Motivation

Source.unfoldResource can close the same resource twice when close(resource) fails. closeStage left the stage marked as open until after close returned, so postStop retried close after the failure.

Modification

Mark the resource as no longer open before invoking close(resource) in closeStage.

Add regression coverage for close failures during normal completion and downstream cancellation.

Result

UnfoldResourceSource now propagates the close failure without attempting to close the same resource again from postStop.

Tests

  • rtk sbt "stream-tests / Test / testOnly org.apache.pekko.stream.scaladsl.UnfoldResourceSourceSpec" / passed
  • rtk scalafmt --mode diff-ref=origin/main / passed with JDK Unsafe deprecation warnings
  • rtk scalafmt --list --mode diff-ref=origin/main / passed with JDK Unsafe deprecation warnings
  • rtk git diff --check / passed
  • rtk sbt headerCreateAll / passed
  • rtk sbt "+headerCheckAll" / passed
  • rtk sbt checkCodeStyle / passed
  • rtk qodercli --help and qodercli stdout review with /tmp/project-review.diff / No must-fix findings
  • rtk sbt validatePullRequest / not completed locally: arm64 host cannot load leveldbjni-all:1.8 native library. The extracted binary reports x86_64/i386 while this host needs arm64; command was stopped after that environment failure.

References

Fixes #3162

Motivation:
Source.unfoldResource could close the same resource twice when close(resource) failed. closeStage left the stage marked as open until after close returned, so postStop retried close after the failure.

Modification:
Mark the resource as no longer open before invoking close(resource) in closeStage. Add regression coverage for close failures during normal completion and downstream cancellation.

Result:
UnfoldResourceSource now reports the close failure without attempting to close the resource again from postStop.

Tests:
- rtk sbt "stream-tests / Test / testOnly org.apache.pekko.stream.scaladsl.UnfoldResourceSourceSpec" / passed
- rtk scalafmt --mode diff-ref=origin/main / passed with JDK Unsafe deprecation warnings
- rtk scalafmt --list --mode diff-ref=origin/main / passed with JDK Unsafe deprecation warnings
- rtk git diff --check / passed
- rtk sbt headerCreateAll / passed
- rtk sbt "+headerCheckAll" / passed
- rtk sbt checkCodeStyle / passed
- rtk qodercli --help and qodercli stdout review with /tmp/project-review.diff / No must-fix findings
- rtk sbt validatePullRequest / not completed locally: arm64 host cannot load leveldbjni-all 1.8 native library (available binary reports x86_64/i386, needs arm64); command was stopped after that environment failure

References:
Fixes apache#3162

@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 69e5216 into apache:main Jun 25, 2026
9 checks passed
@He-Pin He-Pin deleted the issue-3162-unfold-resource-close branch June 25, 2026 03:22
@He-Pin He-Pin added the t:stream Pekko Streams label Jun 25, 2026
@He-Pin He-Pin added this to the 2.0.0-M4 milestone Jun 25, 2026
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.

UnfoldResourceSource: resource can be closed twice when close() throws

2 participants