Skip to content

Use shared lock for asset transfer and render-request bundle handling #2463

@AbanoubGhadban

Description

@AbanoubGhadban

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:

  1. Asset transfer (worker.ts:340) acquires a global 'transferring-assets' lock.
  2. 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.tsawait lock('transferring-assets') (line 340)
  • Render-request lock: packages/react-on-rails-pro-node-renderer/src/worker/handleRenderRequest.tsawait 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.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions