Repository navigation
Conversation
This comment has been minimized.
This comment has been minimized.
52b4937 to
0d6e2b6
Compare
There was a problem hiding this comment.
🔴 Smart CDN V2 tenants can keep serving stale bytes when an object changes again while an earlier purge for the same key is still in flight. The purgeCdnCache queue uses pg-boss policy exclusive (registry.ts:238), keyed by type/tenant/bucket/objectName. That policy silently drops a new job while one with the same key is queued or active. Fix: keep each per-object purge sent after a commit from being dropped by a purge already in flight, e.g. use a non-dropping policy for this queue (or a key that is unique per write) and accept duplicate purges as cheap.
Why this was flagged
Overwrite write1 commits and notify enqueues purge P1 with the key object/<tenant>/<bucket>/<name>. While P1 is active in cdnCacheManager.purge (up to the 10s abort budget), a second upsert or a delete of the same object commits and sends P2. pg-boss exclusive (registry.ts:238, options.ts:14-15) skips P2 silently because P1 holds the key. If P1 reaches the edge before write2 commits, a read in that gap caches write1's bytes, and no later purge ever clears them. The new comment at purge-cdn-cache.ts:51-52 says V2 has no other invalidation signal. On the base branch, object writes did not depend on this queue: V1 invalidation went through webhooks, which do not have this policy. The idempotency key was built for v1 manual or bucket purges, where dropping a duplicate was harmless.
Verification: run-migrations.ts:194 confirms that "v12's exclusive unique index spans created..active". So an enqueue is dropped while the earlier job is active, not only while it is queued. This change routes per-object writes into that queue. Before it, the only producer was the manual admin purge at storage.ts:325. V2 tenants then serve stale content until the edge TTL runs out.
There was a problem hiding this comment.
Beyond the inline findings, I checked whether billing/audit logging could be lost now that logLifecycleEvent has moved out of sendWebhook. It isn't lost. Outside tests, the only callers of sendWebhook/sendWebhookBatch are the new notify/notifyBatch in lifecycle-events.ts, and both log before sending. The lifecycle executor already calls logLifecycleEvent directly.
Extended reasoning...
Searching src showed that outside tests, the only callers of the class-level sendWebhook/sendWebhookBatch are notify/notifyBatch (lifecycle-events.ts:57 and :72). Both call logLifecycleEvent before sending, so turning off webhooks does not stop audit logging.
Findings marked 🟡 are optional suggestions and need no follow-up push.
| */ | ||
| export async function purgeObjectCache(object: PurgeableObject): Promise<void> { | ||
| try { | ||
| await PurgeCdnCache.send(toPurgeOptions(object)) |
There was a problem hiding this comment.
⚪ Severity: LOW
The purge queue is exclusive and keys jobs by tenant, bucket, and object, so a repeat send while the first job is queued or running is silently dropped. If another write or delete lands after the first purge but before its job settles, the second invalidation is lost and stale bytes can remain served.
Helpful? Add 👍 / 👎
💡 Fix Suggestion
Suggestion: The exclusive queue policy with a tenant/bucket/object idempotency key silently drops a second purge that arrives while the first job is queued or running. Change how purge jobs are deduplicated so a later write or delete still triggers a purge. Options: (1) switch the queue policy to one that allows one queued job plus one active job, such as pg-boss stately or short, so a new purge can queue behind the running one. (2) Add a time-bucket or version component, such as the object version or an updated-at timestamp, to the idempotency key. (3) Use a short singleton window so purges that arrive after the first job starts are not dropped. This needs changes to the queue registration in src/storage/events/registry.ts and to the idempotency key logic in the event class. It is not a fix at the send call on line 58.
Coverage Report for CI Build 46296465498Coverage increased (+0.03%) to 88.712%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
a2d9cc3 to
9f31910
Compare
9f31910 to
aa5bcb5
Compare
What kind of change does this PR introduce?
Feature
What is the current behavior?
What is the new behavior?
Together, this lets a project move from the old webhook-driven cache (Smart CDN V1) to the new active-purge cache (Smart CDN V2) without a hard cutover. Both behaviors run side by side during the migration. Once every project is on V2, webhooks can be turned off.
If no purge endpoint is configured, the purge step does nothing, so this has no effect without that extra configuration.