Remote JobCancel() can be silently lost while the notifier is reconnecting (no durable-poll fallback)
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 45/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Go
- Étoiles
- 5.7k
- Forks
- 179
- Merge moyen
- 1 j 18 h
- PR mergées (30 j)
- 19
Préparer son environnement
Nous n'avons pas encore vérifié les fichiers d'installation de ce projet. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de riverqueue/river
-
River job stuck at runningOuverte
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
riverqueue/river#1258 · 7 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
riverqueue/river#1225 · 14 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 52/100
riverqueue/river#1185 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 52/100
riverqueue/river#1183 · 2 réactions ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 30/100
riverqueue/river#1167 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de riverqueue/river
Issues similaires
-
Remove CAAPFOuvertekind/chore kind/cleanup needs-area
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
rancher/turtles#2848 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
Les mainteneurs répondent en général sous 1 jour
-
priority: low 🌱 type: enhancement 💅🏼
Difficulté 2/5 Une demi-journée Accessibilité débutants 84/100
nebari-dev/llm-serving-pack#199 ·
Les mainteneurs répondent en général sous 3 jours
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
kedacore/keda#8225 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour