Skip to content

Add 30s timeout to PeriodicJobEnqueuer insertBatch#1251

Merged
brandur merged 2 commits into
riverqueue:masterfrom
NanoBjorn:periodic-enqueuer-timeout
May 15, 2026
Merged

Add 30s timeout to PeriodicJobEnqueuer insertBatch#1251
brandur merged 2 commits into
riverqueue:masterfrom
NanoBjorn:periodic-enqueuer-timeout

Conversation

@NanoBjorn
Copy link
Copy Markdown
Contributor

Previously, PeriodicJobEnqueuer.insertBatch passed the raw service context directly to Begin/Insert/Commit, with no per-batch deadline (unlike all other calls to the db). If the underlying connection stalled, the enqueuer would hang indefinitely, halting all periodic job insertion until the process was restarted. We have observed this issue multiple times during RW-RO failovers or temporary network unavailability, stalls in our case could last from minutes to hours

Wrapped the DB calls in context.WithTimeout(ctx, riversharedmaintenance.TimeoutDefault) (30s), matching the pattern already used by JobScheduler and JobRescuer.

Previously, `PeriodicJobEnqueuer.insertBatch` passed the raw service
context directly to `Begin`/`Insert`/`Commit`, with no per-batch
deadline. If the underlying connection stalled, the enqueuer would
hang indefinitely, halting all periodic job insertion until the
process was restarted.

Wrap the DB calls in `context.WithTimeout(ctx,
riversharedmaintenance.TimeoutDefault)` (30s), matching the pattern
already used by `JobScheduler` and `JobRescuer`.
@NanoBjorn
Copy link
Copy Markdown
Contributor Author

@brandur I would also like to hotfix this into older version we use (v0.18.0), can we do this after merge?

@NanoBjorn
Copy link
Copy Markdown
Contributor Author

cc @bgentry

Copy link
Copy Markdown
Contributor

@brandur brandur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, forgot to hit the submit button on my review.

Comment thread CHANGELOG.md Outdated

### Fixed

- Wrap `PeriodicJobEnqueuer.insertBatch` database calls in a 30-second timeout. Previously, a stalled pgx `Begin`/`Insert`/`Commit` could hang the periodic enqueuer indefinitely, halting all periodic job insertion until the process was restarted or leader re-elected.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a link to the PR here like the other entries have?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@NanoBjorn NanoBjorn requested a review from brandur May 15, 2026 10:59
@brandur brandur merged commit df28c1c into riverqueue:master May 15, 2026
12 checks passed
@brandur brandur mentioned this pull request May 15, 2026
brandur added a commit that referenced this pull request May 15, 2026
Do a release containing context enhancements in #1251.

[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants