fix(retry): address PR #12 code review feedback

- Add 'stepped' backoff strategy that uses RETRY_BACKOFF_DELAYS directly
- Update rsocket config to use 'stepped' instead of 'exponential'
- Clarify maxWebSocketListeners calculation (8 core + 10 dynamic + 2 buffer)
- Document maxSocketClientListeners calculation (20 core + 20 dynamic + 10 buffer)
- Change 'exponential backoff' to 'custom progressive backoff' in docs
- Add comprehensive tests for getRetryDelayWithJitter and getAllRetryDelaysWithJitter
- Fix existing test type errors (onRetry mock, always/never predicates)
This commit is contained in:
Claude
2026-01-20 13:05:13 +00:00
parent 2d84da8bd7
commit b719349c57
4 changed files with 178 additions and 11 deletions
+13 -4
View File
@@ -33,7 +33,7 @@ const RETRY_JITTER_FACTOR = 0.15
/**
* Backoff strategies
*/
export type BackoffStrategy = 'exponential' | 'linear' | 'constant' | 'fibonacci'
export type BackoffStrategy = 'exponential' | 'linear' | 'constant' | 'fibonacci' | 'stepped'
/**
* Retry configuration options
@@ -152,6 +152,14 @@ export function calculateDelay(
break
}
case 'stepped': {
// Uses pre-defined delay array directly (ignores baseDelay/multiplier)
// Falls back to last delay if attempt exceeds array length
const index = Math.min(attempt - 1, RETRY_BACKOFF_DELAYS.length - 1)
delay = RETRY_BACKOFF_DELAYS[index] ?? RETRY_BACKOFF_DELAYS[0] ?? baseDelay
break
}
default:
delay = baseDelay
}
@@ -646,14 +654,15 @@ export const retryConfigs = {
},
/**
* RSocket-style retry (uses RETRY_BACKOFF_DELAYS from Defaults)
* Delays: 1s, 2s, 5s, 10s, 20s with jitter
* RSocket-style retry with stepped delays
* Uses fixed delay array: 1s, 2s, 5s, 10s, 20s (with ±15% jitter)
* Unlike exponential, this uses exact delays from RETRY_BACKOFF_DELAYS
*/
rsocket: {
maxAttempts: RETRY_BACKOFF_DELAYS.length,
baseDelay: RETRY_BACKOFF_DELAYS[0],
maxDelay: RETRY_BACKOFF_DELAYS[RETRY_BACKOFF_DELAYS.length - 1],
backoffStrategy: 'exponential' as const,
backoffStrategy: 'stepped' as const,
jitter: RETRY_JITTER_FACTOR,
},
}