Motivation
Flow.recoverWithRetries 仅接受重试次数和恢复 PartialFunction,没有退避(backoff)或延迟参数。每次重试立即执行,在恢复源也是故障源时会导致快速连续失败,浪费资源。
当前代码行为
Flow.scala 中的签名:
// Flow.scala:950-953
def recoverWithRetries(
attempts: Int,
pf: PartialFunction[Throwable, Graph[SourceShape[Out], NotUsed]]
): Repr[Out]
实现(Ops.scala:2286-2348)中仅有 maximumRetries 计数,无 delay/backoff 参数。失败后立即切换到恢复 Source。
预期行为
提供带退避参数的重载版本,例如:
def recoverWithRetries(
attempts: Int,
minBackoff: FiniteDuration,
maxBackoff: FiniteDuration,
randomFactor: Double,
pf: PartialFunction[Throwable, Graph[SourceShape[Out], NotUsed]]
): Repr[Out]
代码证据
stream/src/main/scala/org/apache/pekko/stream/scaladsl/Flow.scala:950-953 — 当前签名
stream/src/main/scala/org/apache/pekko/stream/impl/fusing/Ops.scala:2286-2348 — 实现,仅有 maximumRetries
复现方式
当恢复 Source 本身需要时间初始化(如网络连接)时,立即重试会导致快速连续失败。
影响范围
- 模块:
pekko-stream
- 影响使用
recoverWithRetries 进行故障恢复的流
- 在恢复源依赖外部资源时,无退避重试可能加剧故障
Motivation
Flow.recoverWithRetries仅接受重试次数和恢复 PartialFunction,没有退避(backoff)或延迟参数。每次重试立即执行,在恢复源也是故障源时会导致快速连续失败,浪费资源。当前代码行为
Flow.scala中的签名:实现(
Ops.scala:2286-2348)中仅有maximumRetries计数,无 delay/backoff 参数。失败后立即切换到恢复 Source。预期行为
提供带退避参数的重载版本,例如:
代码证据
stream/src/main/scala/org/apache/pekko/stream/scaladsl/Flow.scala:950-953— 当前签名stream/src/main/scala/org/apache/pekko/stream/impl/fusing/Ops.scala:2286-2348— 实现,仅有maximumRetries复现方式
当恢复 Source 本身需要时间初始化(如网络连接)时,立即重试会导致快速连续失败。
影响范围
pekko-streamrecoverWithRetries进行故障恢复的流