Skip to content

Flow.recoverWithRetries 缺少退避/延迟参数 #3220

Description

@He-Pin

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 进行故障恢复的流
  • 在恢复源依赖外部资源时,无退避重试可能加剧故障

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions