Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Notifier spins without backoff when the Start context ends by deadline

Chiusa Adatta ai principianti
#1,493 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Una pull request collegata è già stata integrata.

  • #1495 di @brandur — integrata

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go, postgresql
Ambito
backend, databases

Direzione di ricerca

Inizia da internal/notifier/notifier.go, nel ciclo di riconnessione che chiama n.listenAndWait(ctx) e controlla errors.Is(err, context.Canceled). La correzione consiste nel fermare il ciclo quando ctx.Err() non è nil, e nel verificare le altre uscite context.Canceled nello stesso file. Il lavoro è completato quando un context che raggiunge la sua deadline termina Start senza log ripetuti di Error running listener, dimostrato da un test che usa un context.WithTimeout breve.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
  1. Create a client against a healthy Postgres.
  2. ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second), then client.Start(ctx).
  3. 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).

Lingua principale
Go
Stelle
5.8k
Fork
188
Merge medio
22h 44m
PR unite (30g)
95

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di riverqueue/river

Tutte le issue di riverqueue/river

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.