Skip to content

feat(stream): add supervisor strategy support to Throttle costCalculation#3108

Closed
He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:add-throttle-supervisor-strategy
Closed

feat(stream): add supervisor strategy support to Throttle costCalculation#3108
He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:add-throttle-supervisor-strategy

Conversation

@He-Pin

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

Copy link
Copy Markdown
Member

Motivation

The Throttle stage's costCalculation function had no exception handling. If the user-provided cost function threw, the exception propagated directly and failed the stage unconditionally. Unlike other stages (MapAsync, Filter, Log), Throttle did not consult the SupervisionStrategy decider, preventing users from configuring Resume or Restart behavior for bad elements.

Fixes #3101

Modification

  • Add try-catch around costCalculation(elem) with NonFatal handling
  • Add decider lookup via SupervisionStrategy mandatory attribute
  • On Stop: failStage (preserves default behavior)
  • On Resume/Restart: log at debug level and pull next element
  • Mix in StageLogging for observability
  • Add 4 new tests covering Resume, Restart, Stop directives and Enforcing mode

Result

Users can now configure supervision strategy on Throttle to skip elements that cause costCalculation exceptions, matching the behavior of other stages in Pekko Streams.

Tests

sbt "stream-tests / Test / testOnly org.apache.pekko.stream.scaladsl.FlowThrottleSpec"
# 27 tests passed (4 new + 23 existing)

References

Fixes #3101

…tion

Motivation:
The Throttle stage's costCalculation function had no exception handling.
If the user-provided cost function threw, the exception propagated directly
and failed the stage unconditionally. Unlike other stages (MapAsync, Filter,
Log), Throttle did not consult the SupervisionStrategy decider, preventing
users from configuring Resume or Restart behavior for bad elements.

Modification:
- Add try-catch around costCalculation(elem) with NonFatal handling
- Add decider lookup via SupervisionStrategy mandatory attribute
- On Stop: failStage (preserves default behavior)
- On Resume/Restart: log at debug level and pull next element
- Mix in StageLogging for observability
- Add tests for Resume, Restart, Stop directives and Enforcing mode

Result:
Users can now configure supervision strategy on Throttle to skip elements
that cause costCalculation exceptions, matching the behavior of other
stages in Pekko Streams.

Tests:
- sbt "stream-tests / Test / testOnly org.apache.pekko.stream.scaladsl.FlowThrottleSpec"
- 27 tests passed (4 new + 23 existing)

References:
Fixes apache#3101
Inspired by akkadotnet/akka.net#6886
@He-Pin He-Pin marked this pull request as draft June 20, 2026 12:30
@He-Pin He-Pin added the t:stream Pekko Streams label Jun 20, 2026
@He-Pin He-Pin closed this Jun 20, 2026
@He-Pin He-Pin deleted the add-throttle-supervisor-strategy branch June 20, 2026 12:52
@pjfanning pjfanning added the akkadotnet Issue/PR inspired by Akka.net label Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

akkadotnet Issue/PR inspired by Akka.net t:stream Pekko Streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Throttle stage lacks supervisor strategy support for costCalculation exceptions

2 participants