fix(distribution-monitor): tolerate lock timeout on boot-time index check#492
Merged
Merged
Conversation
…heck - Wrap the materialized-view unique-index creation in ensureLatestObservationsIndex, which swallows a 55P03 (lock_not_available) instead of aborting startup. During a rolling deploy a contended REFRESH ... CONCURRENTLY holds an EXCLUSIVE lock; the boot-time SHARE-locking re-check then times out and previously crash-looped the monitor. - Re-throw any other error unchanged. - Add isLockNotAvailable to detect the SQLSTATE through the wrapped driver-error cause chain. - Unit-test both helpers; autoUpdate refreshes the coverage thresholds.
This was referenced Jun 18, 2026
build(deps): bump @lde/distribution-monitor to 0.1.14
netwerk-digitaal-erfgoed/network-of-terms#1877
Merged
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.
Problem
The status monitor crash-loops on startup with:
latest_observationsis a materialized view, and the boot path always runs aCREATE UNIQUE INDEX IF NOT EXISTSto provide the unique index thatREFRESH … CONCURRENTLYrequires. Even theIF NOT EXISTSform must take aSHARElock on the view before it can skip, and that lock conflicts with theEXCLUSIVElock held by aREFRESH … CONCURRENTLYrunning in another instance.During a rolling deploy the old and new pods overlap (default
RollingUpdate,maxUnavailable: 0), so the new pod's index re-check waits on the old pod's refresh. With the per-connectionlock_timeout(30s) introduced earlier, that wait now raises55P03— and because the statement was unguarded, it aborted startup and the monitor crash-looped indefinitely, leaving the status site without availabilities.Fix
Wrap the index creation in
ensureLatestObservationsIndex(), which swallows a55P03lock-timeout and lets startup proceed. Whenever the view is being refreshed the index already exists, so a failed re-check is harmless. Any other error still propagates unchanged.This keeps
RollingUpdate(two overlapping pods) working — no deployment-strategy change needed.Changes
store.ts— extractensureLatestObservationsIndex()(tolerates55P03, re-throws everything else) andisLockNotAvailable()(detects the SQLSTATE through drizzle's wrappedcausechain).store.test.ts— unit tests for both helpers (fast, no lock-wait): swallow vs. re-throw, and SQLSTATE detection across nested causes and non-object inputs.vite.config.ts— autoUpdate raised the coverage thresholds to match.Notes
This addresses the crash-loop. A separate, pre-existing concern remains: the
observationstable has no retention/pruning, and aREFRESH … CONCURRENTLYwas observed wedged for hours — worth its own issue.