Problem
The /upload-assets endpoint and the render-request bundle handler (handleNewBundleProvided) both copy assets into bundle directories, but they use independent locks that don't coordinate with each other:
- Asset transfer (
worker.ts:340) acquires a global 'transferring-assets' lock.
- Render-request bundle handling (
handleRenderRequest.ts:92) acquires a per-bundle lock using bundleFilePathPerTimestamp.
Because these are separate locks, both operations can run concurrently on the same bundle directory — the 'transferring-assets' lock does not block the per-bundle lock and vice versa. Both code paths call copyUploadedAssets() to write files into the bundle directory, so concurrent execution can cause:
- Partial file writes or corrupted assets if both paths write to the same destination file simultaneously
- Unpredictable bundle directory state where some assets come from one operation and others from another
Relevant Code
/upload-assets lock: packages/react-on-rails-pro-node-renderer/src/worker.ts — await lock('transferring-assets') (line 340)
- Render-request lock:
packages/react-on-rails-pro-node-renderer/src/worker/handleRenderRequest.ts — await lock(bundleFilePathPerTimestamp) (line 92)
- Shared lock utility:
packages/react-on-rails-pro-node-renderer/src/shared/locks.ts
Proposed Solution
Unify the locking so that both operations coordinate when writing to the same bundle directory. For example, use per-bundle-directory locks in both code paths so that:
- The
/upload-assets endpoint acquires the per-bundle lock for each target bundle directory before copying assets into it
- The render-request handler continues using its per-bundle lock as it does today
This ensures that for any given bundle directory, only one operation writes assets at a time, preventing race conditions between asset transfer and render-request bundle handling.
Problem
The
/upload-assetsendpoint and the render-request bundle handler (handleNewBundleProvided) both copy assets into bundle directories, but they use independent locks that don't coordinate with each other:worker.ts:340) acquires a global'transferring-assets'lock.handleRenderRequest.ts:92) acquires a per-bundle lock usingbundleFilePathPerTimestamp.Because these are separate locks, both operations can run concurrently on the same bundle directory — the
'transferring-assets'lock does not block the per-bundle lock and vice versa. Both code paths callcopyUploadedAssets()to write files into the bundle directory, so concurrent execution can cause:Relevant Code
/upload-assetslock:packages/react-on-rails-pro-node-renderer/src/worker.ts—await lock('transferring-assets')(line 340)packages/react-on-rails-pro-node-renderer/src/worker/handleRenderRequest.ts—await lock(bundleFilePathPerTimestamp)(line 92)packages/react-on-rails-pro-node-renderer/src/shared/locks.tsProposed Solution
Unify the locking so that both operations coordinate when writing to the same bundle directory. For example, use per-bundle-directory locks in both code paths so that:
/upload-assetsendpoint acquires the per-bundle lock for each target bundle directory before copying assets into itThis ensures that for any given bundle directory, only one operation writes assets at a time, preventing race conditions between asset transfer and render-request bundle handling.