Notifier spins without backoff when the Start context ends by deadline
维护者通常 1 天内回复
已经有一个关联 PR 被合并了。
- #1495 来自 @brandur —— 已合并
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 62/100
调研方向
从 internal/notifier/notifier.go 开始,阅读调用 n.listenAndWait(ctx) 并检查 errors.Is(err, context.Canceled) 的重连循环。修复方法是在 ctx.Err() 非 nil 时停止循环,并检查同一文件中其他的 context.Canceled 退出点。当某个到达截止时间的 context 能让 Start 结束,且不再重复输出 Error running listener 日志时,即视为完成,并以一个使用较短 context.WithTimeout 的测试来证明。
由索引模型根据 Issue 内容生成。
描述
Summary
If the context passed to Client.Start ends by deadline rather than cancellation, the notifier's reconnect loop spins with no backoff and logs Error running listener (will attempt reconnect after backoff) hundreds of thousands of times per second, forever.
Where
internal/notifier/notifier.go (v0.47.0, and unchanged on master at 2f6b27e):
for attempt := 0; ; attempt++ {
if err := n.listenAndWait(ctx); err != nil {
if errors.Is(err, context.Canceled) {
break
}
sleepDuration := serviceutil.ExponentialBackoff(attempt, serviceutil.MaxAttemptsBeforeResetDefault)
n.Logger.ErrorContext(ctx, n.Name+": Error running listener (will attempt reconnect after backoff)", ...)
...
serviceutil.CancellableSleep(ctx, sleepDuration)
}
}
Once ctx is done with context.DeadlineExceeded, listenAndWait fails immediately, the context.Canceled check doesn't match, and CancellableSleep returns immediately because ctx is already done. The loop never exits and never sleeps.
Reproduction
- Create a client against a healthy Postgres.
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second), thenclient.Start(ctx).- Wait past the deadline.
We measured 379,487 Error running listener lines in the 2 seconds after the deadline, and 0 when the same context is cancelled instead. Left running, it wrote a ~476 GB log in about 6 hours before we found it.
Suggested fix
Exit the loop when the context is done for any reason, e.g. if ctx.Err() != nil { break } (or check context.DeadlineExceeded too). The other errors.Is(err, context.Canceled) exits in the notifier may deserve the same treatment.
Workaround
Start River on a context that can only end by cancellation, e.g. runCtx, cancel := context.WithCancel(context.WithoutCancel(ctx)); context.AfterFunc(ctx, cancel).
- 主要语言
- Go
- 星标
- 5.8k
- 派生
- 188
- 平均合并
- 22 小时 44 分钟
- 30 天内合并 PR
- 95
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
riverqueue/river 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
riverqueue/river#1454 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 52/100
riverqueue/river#1411 · 1 条评论 ·
维护者通常 1 天内回复
-
Remote JobCancel() can be silently lost while the notifier is reconnecting (no durable-poll fallback)可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 5/5 一周以上 新手友好度 45/100
riverqueue/river#1358 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
riverqueue/river#1258 · 7 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 45/100
riverqueue/river#1225 · 14 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 1 天内回复
-
kind/bug
难度 1/5 1-3 小时 新手友好度 85/100
kubernetes-sigs/vsphere-csi-driver#4351 ·
维护者通常 1 天内回复
-
component/gpu-kubelet-plugin component/helm needs-triage
难度 2/5 1-3 小时 新手友好度 62/100
kubernetes-sigs/dra-driver-nvidia-gpu#1559 ·
维护者通常 1 天内回复
-
workflow: redundant goroutine in scheduleRetry可能已有人在做 @moodbased 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
JuliusBrussee/caveman#1266 · 2 条评论 ·
维护者通常 1 天内回复