armeria icon indicating copy to clipboard operation
armeria copied to clipboard

Add StreamTimeoutStrategy, StreamTimeoutDecision, and Token-bucket-based timeout limiting strategy

Open sjy982 opened this issue 7 months ago • 1 comments

Motivation

  • Pluggable timeout strategies
    StreamMessage.timeout() currently uses a fixed timeout mode. Different use-cases may require custom logic, so we introduce a StreamTimeoutStrategy interface. The existing StreamTimeoutMode will remain as the default strategy.
  • Token-bucket-based timeout limiting
    To tolerate transient network jitter, a token-bucket strategy can delay timeout until a user-defined number of consecutive delays is reached.

Modifications

  1. Add StreamTimeoutDecision
    • Immutable value object containing: timedOut, hasNextSchedule, nextScheduleTimeNanos.
    • Provides the factory methods:
      TIMED_OUT, NO_SCHEDULE, scheduleAt(long).
  2. Add StreamTimeoutStrategy interface
    • initialDecision(long subscribeTimeNanos) – called once right after subscription.
    • evaluateTimeout(long currentTimeNanos, long lastEventTimeNanos) – called each time the scheduled timer fires.
  3. (TODO) Default (StreamTimeoutMode) and token-bucket strategy implementations
    Will be added in a follow-up commit.

Result

  • Users can pass a custom StreamTimeoutStrategy to StreamMessage.timeout(strategy) to control per-stream timeout behaviour.
  • The existing enum StreamTimeoutMode continues to work as the default.
  • Closes #6237.

sjy982 avatar May 18 '25 10:05 sjy982

🔍 Build Scan® (commit: f80c2515e25db3f84cff92a48a3efcd3fd731714)

Job name Status Build Scan®
build-ubicloud-standard-16-jdk-8 https://ge.armeria.dev/s/vbsdqucj4w3vu
build-ubicloud-standard-16-jdk-21-snapshot-blockhound https://ge.armeria.dev/s/n5uy45bkomyko
build-ubicloud-standard-16-jdk-17-min-java-17-coverage https://ge.armeria.dev/s/7vpqv2cnur2sc
build-ubicloud-standard-16-jdk-17-min-java-11 https://ge.armeria.dev/s/qvuvaqyhxjef4
build-ubicloud-standard-16-jdk-17-leak https://ge.armeria.dev/s/3fbxcvbh4dly2
build-ubicloud-standard-16-jdk-11 https://ge.armeria.dev/s/stqfwqlen5k2c
build-macos-latest-jdk-21 https://ge.armeria.dev/s/2quqym4g77slc

github-actions[bot] avatar May 18 '25 11:05 github-actions[bot]

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 0.00%. Comparing base (8150425) to head (f80c251). Report is 106 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #6245       +/-   ##
============================================
- Coverage     74.46%       0   -74.47%     
============================================
  Files          1963       0     -1963     
  Lines         82437       0    -82437     
  Branches      10764       0    -10764     
============================================
- Hits          61385       0    -61385     
+ Misses        15918       0    -15918     
+ Partials       5134       0     -5134     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Jun 25 '25 01:06 codecov[bot]