Skip to content

fix: run stage cleanup when postStop throws - #3814

Merged
He-Pin merged 1 commit into
apache:mainfrom
He-Pin:fix/stream-cleanup-after-poststop-failure
Nov 29, 2026
Merged

He-Pin merged 1 commit into
apache:mainfrom
He-Pin:fix/stream-cleanup-after-poststop-failure

Conversation

@He-Pin

@He-Pin He-Pin commented Nov 26, 2026

Copy link
Copy Markdown
Member

Motivation

If a local GraphStage postStop hook throws a non-fatal exception, the interpreter skips its internal afterPostStop hook. In particular, a pending asynchronous callback can miss the notification that its stage has detached.

Modification

Handle non-fatal failures from the two stop hooks separately, so internal cleanup runs even if the user hook fails. Keep the existing error log and original cause, preserve stream termination behavior, and continue to let fatal exceptions escape.

Result

A failed local stop hook no longer prevents the interpreter from cleaning up the stage. No public API changes.

Tests

  • The manually stepped regression checks a real pending invokeWithFeedback result, the unchanged downstream completion signal, and one call to each stop hook. It failed on the old implementation and passed with the fix.
  • JDK 17: the two focused suites passed 23/23 on both Scala 2.13.18 and 3.3.9. Scoped style and +headerCheckAll passed locally.

References

Related to #3409, which handles watched sinks. This change covers ordinary stages independently.

@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.

Looks good to me. Skipping afterPostStop also left the stage actor running, substreams not cleaned up and the timers of a TimerGraphStageLogic not cancelled, so this fixes more than the pending callback feedback. One optional nit inline.

Motivation: A non-fatal stage postStop exception should not skip
internal cleanup, including pending callback feedback.

Modification: Catch non-fatal stage stop and cleanup failures
separately. Keep the existing postStop log and give cleanup failures
their own message, preserving the original cause in either case.

Result: Internal cleanup still runs, the two errors are distinguishable,
and normal downstream termination is unchanged. Fatal errors still
escape.

Tests: JDK 17, Scala 2.13.18 and 3.3.9. Focused interpreter lifecycle
and failure-mode suites, including a manually stepped cleanup-log
assertion and the existing pending-feedback regression.

References: PJ's review on apache#3814; apache#3409 covers watched sinks.
@He-Pin
He-Pin force-pushed the fix/stream-cleanup-after-poststop-failure branch from 341cbea to 9d83dd0 Compare November 26, 2026 12:59
@He-Pin
He-Pin requested a review from pjfanning November 26, 2026 13:01

@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 5102aa8 into apache:main Nov 29, 2026
11 checks passed
@He-Pin
He-Pin deleted the fix/stream-cleanup-after-poststop-failure branch November 29, 2026 04:19
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