Notifier spins without backoff when the Start context ends by deadline
Mantenedores costumam responder em até 1 dia
Um pull request relacionado já foi integrado.
- #1495 de @brandur — integrado
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 62/100
Direção de pesquisa
Comece em internal/notifier/notifier.go, no loop de reconexão que chama n.listenAndWait(ctx) e verifica errors.Is(err, context.Canceled). A correção é parar o loop quando ctx.Err() não for nil e verificar as outras saídas com context.Canceled no mesmo arquivo. Está concluído quando um context que atinge o seu deadline encerra Start sem logs repetidos de Error running listener, demonstrado por um teste que usa um context.WithTimeout curto.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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).
- Linguagem predominante
- Go
- Estrelas
- 5.8k
- Forks
- 188
- Merge médio
- 22h 44min
- PRs com merge (30d)
- 95
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de riverqueue/river
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
riverqueue/river#1454 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 52/100
riverqueue/river#1411 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Remote JobCancel() can be silently lost while the notifier is reconnecting (no durable-poll fallback)Talvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 45/100
riverqueue/river#1358 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
River job stuck at runningAberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
riverqueue/river#1258 · 7 comentários ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 45/100
riverqueue/river#1225 · 14 comentários ·
Mantenedores costumam responder em até 1 dia
Todas as issues de riverqueue/river
Issues semelhantes
-
Named Tuple element with a space in its name fails to parseTalvez já em andamento @spicysharkco assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
ClickHouse/clickhouse-go#2073 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
-
ci: nothing regenerates the Go contract types, so a hand-edit to types.gen.go passesTalvez já em andamento @shaiknoorullah assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
shaiknoorullah/hg-mono#993 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
type:bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
CarlosDanielDev/aiacc#78 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100