Repository navigation
fix(plugin-cloud-storage): don't leave skipCloudStorage on a reused context - #17700
luantaraschi wants to merge 1 commit into
Conversation
…ontext The afterChange hook sets `skipCloudStorage` on `req.context`, then calls a nested `payload.update()`. That runs `createLocalReq`, which reassigns `req.context` to a fresh copy — so the `finally` cleared the flag off the copy and left it on the original object. When a caller passes one `context` object across several Local API creates, `createLocalReq` binds that same object to `req.context`, so the leftover flag makes every later upload return early. The documents are written with correct filenames and sizes, but no bytes reach storage and nothing is logged.
|
Thanks for adding an integration test that verifies the actual stored objects. This directly covers the silent data-loss behavior from #17546. There is still one context reference left polluted after the fix. The nested This can remain visible to delete contextWithFlag.skipCloudStorage
if (req.context !== contextWithFlag) {
delete req.context.skipCloudStorage
}It would be useful to combine that cleanup with this PR's integration test and add an assertion covering the rebound request context. Separately, |
|
You are right about the rebound context, and #17558 got there first.
Reading #17558 properly: opened 29 July against my 6 August, same captured reference ( So I would rather not have two PRs racing on the same file. Close this one in favour of #17558 whenever it suits you. The one thing here that #17558 does not have is the integration test. It drives three real On |
|
Thanks for checking this so carefully. Agreed: #17558 should be the implementation and #17700 can close in its favour. The integration test is worth carrying over before merge because it catches the actual missing-byte regression through real creates, which complements #17558’s unit coverage. No need to make a claim about |
|
Closing in favour of #17558, which was open first and clears the flag off both the captured context and the rebound one, where this only did the first. Two PRs racing on the same file is not worth it. The integration test here does not exist over there, so I have pointed at it from that PR. If it lands without it I will send it on its own. Thanks @cbratschi for reading it that carefully. |
Fixes #17546.
What
Passing one
contextobject across several Local APIcreate()calls on an upload collection uploads only the first file. Every later create succeeds, writes a fully-populated document (filename,mimeType,sizes,url), and puts nothing in storage, with no error and no log line.@edrpls traced the mechanism precisely in the issue; this confirms it and fixes the last link.
The chain
createLocalReqassigns the caller'scontexttoreq.contextby reference when the fresh req has none.getRequestContextreturnscontextunchanged in that branch.req.context.skipCloudStorage = true, so it is now set on the caller's object.payload.update({ ..., req })runscreateLocalReqagain on that same req.req.contextis non-empty now, so line 139 reassignsreq.context = { ...req.context, ...context }, which is a new object.finally { delete req.context.skipCloudStorage }deletes it from that new object.create()binds it toreq.contextagain, the hook returns early at its first line, and no upload happens.Step 3 is the one that's easy to miss: the reassignment happens on the same
req, soreq.contextsilently stops pointing at what step 2 mutated.The fix
Capture the reference the flag is set on, and clear it from that:
The recursion guard still works, because the nested
createLocalReqcopiesreq.contextincluding the flag, so the nested hook still sees it and returns early. Only the cleanup changes.I deliberately did not touch
getRequestContext. Handing the caller's object over by reference is what lets hooks write back into a caller's context, and changing that would be a much broader behavioural change than this bug warrants.Verified by running it
Added
uploads every file when one context object is reused across createstotest/plugin-cloud-storage/int.spec.ts. Three sequential creates sharing onecontext, thenHeadObjectagainst the bucket for every file and every generated size.Run against LocalStack + MongoDB in Docker:
Tests 1 passedafterChange.tsTests 1 failedThe control failure is the reported damage, not a proxy for it:
The first file (
image.png) verifies fine; the second one and its sizes are absent from the bucket while its document row exists. Reverting thefinallyline alone is enough to reproduce.Full suite after the change:
Test Files 2 passed · Tests 35 passed | 3 todo (38).Note on the assertion order
The test checks the bucket before asserting that
sharedContextis clean. I had it the other way round first, and the control then failed on the context assertion. That is technically correct, but it would have let a future regression report the internal symptom instead of the missing object. The bucket check is the one that describes what users lose.What I did not verify
I ran the
plugin-cloud-storagesuite only, on MongoDB with the S3 adapter against LocalStack. I did not run the otherstorage-*suites (azure, gcs, r2, vercel-blob). The change is in the shared hook, so they exercise the same path, but I'm flagging it rather than implying I checked. Same for a real S3/R2 endpoint; the reporter covered R2.Checklist