Remote JobCancel() can be silently lost while the notifier is reconnecting (no durable-poll fallback)
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 45/100
Direção de pesquisa
Start with internal/notifier/notifier.go and the Client.JobCancel() path, then inspect JobRescuer and the cancel_attempted_at metadata described in the issue. Review related discussions in #1135 and #630 before choosing between client-side polling and rescuer changes. Done means a cancellation remains observable when PostgreSQL LISTEN/NOTIFY is unavailable during reconnect, with convergence sooner than the general stuck-job window.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Summary
Client.JobCancel() delivers its cancellation signal to a running job's executor exclusively via Postgres LISTEN/NOTIFY. If the notifier happens to be mid-reconnect (its exponential backoff loop, internal/notifier/notifier.go) at the moment the NOTIFY is sent, that specific signal is lost — not delayed — because Postgres NOTIFY is fire-and-forget and only reaches sessions that are actively LISTENing at commit time. The job keeps running unaware it was cancelled, and the only recovery is JobRescuer's stuck-job sweep, which defaults RescueStuckJobsAfter to one hour when unconfigured.
This is a real, reproducible failure mode, not a theoretical one — details and evidence below.
Mechanism
notifier.go's run loop treats any listener error (a transient connection reset, a pooler cycling the backend, a brief network blip, etc.) as cause to disconnect and retry with exponential backoff:0.5s, 1s, 2s, 4s, 8s, 16s, 32s, 64s(rivershared/util/serviceutil.ExponentialBackoff,MaxAttemptsBeforeResetDefault = 7; the run loop's ownattemptcounter starts at 0, one step earlier thanExponentialBackoff's doc comment assumes, so the very first retry lands at 0.5s before the schedule settles into the documented 1s→64s cycle on later retries). Each connect/listen attempt also has its own 10s timeout (listenerTimeout).- While the notifier is in that backoff window, it is not
LISTENing onriver_control(or any topic) at all. - If
JobCancel()is called during that window, itsNOTIFYcommits successfully but has no active listener to reach — it is gone.JobCancel()itself has no visibility into notifier connectivity and returns success regardless (correctly — the durable state write,cancel_attempted_atin the job's metadata, did succeed). - The running job's executor never observes
ctx.Done(). It keeps running until it completes normally, or untilJobRescuereventually rescues it — up to an hour later by default, sinceRescueStuckJobsAfterisn't tied tocancel_attempted_atspecifically; it's the same general stuck-job window.
Confirmed by reading the source directly (not inferring from behavior) against v0.44.0 — this is not a stale/fixed-since concern; I checked master too (currently a few commits past v0.44.1, none touching notifier/producer/rescuer).
Evidence
Found while investigating an intermittent CI failure in a compatibility test harness that exercises River under session-mode PgBouncer pooling (session-mode pins one backend connection per client for its whole life, which is the documented-correct pooling mode for River's LISTEN-dependent components per the River PgBouncer docs). The harness's own JobCancel()-driven cancellation test would intermittently hang until its bounded wait (20s) expired, under CPU-constrained CI runners. That investigation turned up two separate, independently-confirmed issues on our side, only one of which is River's: (1) our own connection-pool sizing was too tight under load — our bug, already fixed; (2) the mechanism described in this issue, confirmed present in River's source and unaffected by our pool fix.
For the mechanism in this issue specifically: I'm reporting it because I read and understand the code path, not because I caught the notifier's reconnect/backoff loop firing at the exact instant of a specific test hang (that's a narrow window to catch live, and I don't want to overclaim a live capture I don't have). What I can say with confidence: NOTIFY semantics in Postgres are fire-and-forget by design (not River-specific), the notifier's backoff loop is real and unchanged as of the current master, and the two combine straightforwardly into exactly the failure mode described above with no additional assumptions needed.
Suggested direction
#1135 raised a related situation earlier this year, and the response there (also echoing the original design discussion in #630 back in 2024) was that a durable-poll fallback for all running jobs on all clients is rightly seen as prohibitive query load for what's framed as a rare event. I think that's the right call for that shape of fallback — but there's a narrower version worth considering:
A much cheaper, targeted version of that idea: poll only the (typically tiny) set of jobs that actually have metadata->>'cancel_attempted_at' set — i.e., jobs someone has already explicitly tried to cancel — rather than every running job. That set should be empty almost all the time in a healthy system, making the query cost negligible in the common case while providing deterministic convergence in the rare case a NOTIFY is genuinely lost. This could live client-side (each client polling its own currently-running job IDs against that condition) or as an addition to the existing rescuer's responsibilities with a much shorter, cancel-specific window than the general stuck-job RescueStuckJobsAfter.
Happy to discuss further or take a stab at a PR if there's interest in this direction.
- Linguagem predominante
- Go
- Estrelas
- 5.7k
- Forks
- 179
- Merge médio
- 1d 18h
- PRs com merge (30d)
- 19
Preparar o ambiente
Ainda não verificamos os arquivos de configuração deste projeto. 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
-
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
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 52/100
riverqueue/river#1185 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 52/100
riverqueue/river#1183 · 2 reações ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 30/100
riverqueue/river#1167 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
Todas as issues de riverqueue/river
Issues semelhantes
-
Remove CAAPFAbertakind/chore kind/cleanup needs-area
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
rancher/turtles#2848 · 3 comentários ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia
-
good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
Mantenedores costumam responder em até 1 dia
-
priority: low 🌱 type: enhancement 💅🏼
Dificuldade 2/5 Meio dia Facilidade para iniciantes 84/100
nebari-dev/llm-serving-pack#199 ·
Mantenedores costumam responder em até 3 dias
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
kedacore/keda#8225 · 1 comentário ·
Mantenedores costumam responder em até 1 dia