Repository navigation
fix(delivery): stop polling the database every second while nothing is configured - #631
Merged
Merged
Conversation
…s configured Webhook and audit sink delivery each ran a one second loop on every replica since 0.23.0, even with no endpoint or sink, which kept pooled connections open and a serverless Postgres from scaling down. Both loops now poll every second only while an endpoint exists or a sink is enabled, and every 30 seconds otherwise with one read. Creating or enabling an endpoint or sink wakes the local loop at once. Dispatch no longer runs while no endpoint exists, so creating the first endpoint moves the dispatch cursor to the newest event under the dispatch lock, keeping the rule that turning webhooks on replays no history. Closes #630
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.
Closes #630.
Problem
Since 0.23.0,
startWebhookDeliveryandstartAuditSinkDeliveryeach run a one second loop on every replica, even when no webhook endpoint or audit sink exists. Each idle webhook tick opens two transactions (advisory lock and cursor read, then aFOR UPDATE SKIP LOCKEDclaim). On a serverless Postgres this keeps pooled connections open and the database from scaling down. On our own Aurora Serverless v2 cluster with four tasks, connections went from 6 to 12 the moment the tasks moved to 0.23.0, and the database bill roughly doubled.Change
src/lib/deliveryPoller.ts: asetTimeoutloop that runs the next tick after 1 second when the last one reported work to watch for and after 30 seconds when it did not. Ticks never overlap,wake()runs one at once (or right after the one in flight), and a rejected tick counts as idle.updateSink's "tried at once" contract.Latency is unchanged once something is configured. Other replicas notice a new endpoint or sink within 30 seconds, and the replica that took the write starts at once.
Checks
npm run typecheck,npm run lint,npm run format:check,npm run build: passnpm run coverage: 206 files, 3662 tests pass; lines 99.32%, branches 95.94%tests/unit/lib/deliveryPoller.spec.tscovers cadence, no overlap, wake while idle and while running, rejection and stop. Service tests cover the idle tick reading only a count, the first-endpoint cursor reset, the cursor left alone when an endpoint exists, a sink in backoff staying busy, hourly pruning, and wake on create.Dependency fix
CI's production audit (
npm audit --omit=dev --audit-level=high) started failing on new advisories forminimatch(GHSA-cf2h-pxjq-68xw and others, high) andglob(GHSA-qxr8-q827-836c, moderate), reached throughsequelize-cli>js-beautify. This fails dependabot's #609 too. The second commit is a lockfile-onlynpm audit fix: minimatch 11.0.3 to 11.0.10, glob 14.0.3 to 14.0.7, @isaacs/nonrecursive-glob-match 1.0.3 to 1.1.0. Build, typecheck, lint and the full suite pass on it, and the audit reports 0 vulnerabilities.