PeriodicJobEnqueuer logs ERROR "Error starting transaction: context canceled" when the client stops during the leader's staggered start
Mantenedores costumam responder em até 1 dia
Um pull request relacionado já foi integrado.
- #1577 de @brandur — integrado
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 66/100
Direção de pesquisa
O ERROR vem de insertBatch em internal/maintenance/periodic_job_enqueuer.go, que chama s.exec.Begin(ctx) depois que StaggerStart retorna com um contexto cancelado. Comece lendo a espera do stagger e o caminho de inserção do job de início, e verifique como Client.Stop cancela os serviços de manutenção. Está pronto quando uma parada durante o stagger do líder não registra nenhum ERROR, mas uma falha real do banco de dados continua registrando.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
### What happens
When a client that has just become the leader is stopped (SIGTERM → Client.Stop or the cancellation of the context passed to Client.Start) within the first ~0.1–2.5 s, the log gets an ERROR line even though the stop is a normal, requested shutdown:
{"level":"ERROR","msg":"maintenance.PeriodicJobEnqueuer: Error starting transaction","error":"context canceled"}
Outside that window the shutdown log is clean.
Why (as far as we can tell from the source)
The maintenance services start with StaggerStart, a cancellable sleep of a random 0–1 s per service, in sequence.
Client.Stop (and the cancellation of the start context) cancels the context of the maintenance services at once.
PeriodicJobEnqueuer wakes up from the stagger with the cancelled context and still goes on to insert the start jobs (RunOnStart periodic jobs): insertBatch calls s.exec.Begin(ctx), which fails with context.Canceled, and the error is logged at ERROR (internal/maintenance/periodic_job_enqueuer.go, insertBatch, "Error starting transaction").
Seen on v0.49.0; the same code is in v0.51.0.
Reproduction
A client with at least one PeriodicJob with RunOnStart: true, alone in the database so it becomes the leader at once.
Start it and stop it about 100 ms after it reports it is the leader (e.g. a process that gets SIGTERM right after its readiness probe).
Repeat a few times: most runs log the ERROR line above.
Expected
A requested stop does not log an error. For example, the enqueuer could return without inserting when ctx.Err() != nil after the stagger (or before Begin), or log a context cancellation during stop at a lower level, as other maintenance services do on shutdown.
Workaround we use
Our runner starts the client on a context that is not cancelled by the process shutdown and, before calling Stop, waits (bounded, a few seconds) until the leader's start jobs are in river_job or another client leads. It works, but it couples the shutdown to a database poll and delays a SIGTERM that arrives right after start.
Environment: River v0.49.0, riverpgxv5, PostgreSQL 18, Go 1.27.
Claude find it, he's always finding
- Linguagem predominante
- Go
- Estrelas
- 5.9k
- Forks
- 197
- Merge médio
- 1d 6h
- PRs com merge (30d)
- 111
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
-
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 · 1 comentário · 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
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 69/100
open-telemetry/opentelemetry-go-compile-instrumentation#1713 ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
JakeChampion/lang#14392 ·
Mantenedores costumam responder em até 1 dia
-
agent-butler-finding bug
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 84/100
jordansmall/spindrift#6557 ·
Mantenedores costumam responder em até 1 dia
-
[Bug] Custom tool truncation leaves unused stream copies openTalvez já em andamento @OUAO-FRANK assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia