fix(selfhost): gate the queue consumer on env readiness at boot - #5050
Merged
Conversation
Both queue backends self-heal a foreground job left over-deferred across a restart by releasing it and kicking the pump once at boot, inside queue construction/init() itself. That can invoke consume() before `env` is assigned further down in main(), dereferencing undefined and surfacing as a misleading generic job_error right after a container restart. consume() now awaits an envReady promise resolved once env is fully assigned. Closes #5049
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5050 +/- ##
=======================================
Coverage 94.16% 94.16%
=======================================
Files 463 463
Lines 39429 39429
Branches 14384 14384
=======================================
Hits 37128 37128
Misses 1646 1646
Partials 655 655
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
consumeinsrc/server.ts) capturesenv, which isn't assigned until ~250 lines / several awaited boot steps after the queue backend is constructed.releaseStaleForegroundDeferrals()once at boot (in addition to its normal periodic sweep), which can callkickAll()->consume(message)->processJob(env, ...)beforeenvis set, dereferencingundefined.job_erroraudit event (TypeError: Cannot read properties of undefined) right after a container restart, only when a foreground job happened to be sitting deferred and release-eligible at that exact moment — self-heals on the very next retry, masking the real cause.consumenow awaits anenvReadypromise, resolved immediately afterenvis fully assigned, so an early release just waits instead of dereferencingenvearly. Confined entirely toserver.ts, which is shared by both queue backends — no changes needed inpg-queue.ts/sqlite-queue.ts.Closes #5049
Test plan
npm run typecheck— cleannpm run test:coverage(full, unsharded) — 717 files / 14146 tests passed, 0 failuresnpm run test:ci(full gate, incl. UI lint/typecheck/test/build, migrations/schema-drift/openapi/docs-drift checks) — greennpm audit --audit-level=moderate— 0 vulnerabilitiessrc/server.tsis incodecov.yml's ignore list (self-host process entry; validated by the Docker boot smoke test in.github/workflows/selfhost.yml, not unit-coverable without booting a real server/subprocess) — no dedicated unit test added for this exact race, consistent with how the rest of that file is handled.