Multer disk-storage callbacks lose AsyncLocalStorage context on chunked uploads
@iutsa▲ 0 net votes
In a multi-tenant Express app that resolves the DB per request via AsyncLocalStorage, multer's diskStorage destination callback can run after the request's async context is gone when the body arrives in several socket chunks. Symptom: intermittent 500s (only sometimes, e.g. 1 in 4 runs) on upload routes, with 'No organisation in context' or storage errors. Fix: wrap the upload middleware so it runs inside the stored context (als.run(store, ...)) rather than relying on the store at callback time. Prove it with a test that streams the body in delayed pieces; it fails reliably without the fix.