Skip to content

Claude/fix r2 mount error sr dsd#205

Open
piffie wants to merge 11 commits intocloudflare:mainfrom
mc2ventures:claude/fix-r2-mount-error-SrDsd
Open

Claude/fix r2 mount error sr dsd#205
piffie wants to merge 11 commits intocloudflare:mainfrom
mc2ventures:claude/fix-r2-mount-error-SrDsd

Conversation

@piffie
Copy link

@piffie piffie commented Feb 8, 2026

No description provided.

piffie and others added 11 commits February 3, 2026 23:39
…nflict

Multiple concurrent requests (e.g. the loading-page waitUntil + the next
polling request) can both call mountR2Storage before the first one finishes.
Each call to sandbox.mountBucket() appends credentials to the s3fs passwd
file, so concurrent calls produce duplicate entries and s3fs refuses to
mount with: "there are multiple entries for the same bucket(default) in
the passwd file."

This adds a module-level in-flight promise that coalesces concurrent mount
calls: only the first caller actually attempts the mount, while subsequent
callers await the same promise. The lock is released in a finally block so
retries are possible after failures.

https://claude.ai/code/session_01E5t9gPHDGGrTUWeagkDjVo
fix: prevent concurrent R2 mount attempts causing s3fs passwd file co…
Two issues caused the "multiple entries for the same bucket(default) in
the passwd file" s3fs error:

1. sandbox.mountBucket() appends credentials to the s3fs passwd file on
   every call.  Because the container persists across Worker invocations
   (keepAlive / sleepAfter), stale entries from previous mounts accumulate
   and s3fs refuses to mount.  Fix: clear /etc/passwd-s3fs and
   ~/.passwd-s3fs before each mount attempt.

2. Concurrent requests (e.g. the loading-page waitUntil + the next polling
   request) can both call mountR2Storage before the first one finishes,
   producing parallel mountBucket() calls that each append entries.
   Fix: coalesce concurrent callers behind a single in-flight promise.

https://claude.ai/code/session_01E5t9gPHDGGrTUWeagkDjVo
…rDsd

fix: prevent duplicate s3fs passwd entries on R2 mount
…uplication

sandbox.mountBucket() manages the s3fs passwd file from the orchestration
layer outside the container and appends a new credential entry on every
call.  Because the container persists across Worker invocations the entries
accumulate and s3fs refuses to mount with "multiple entries for the same
bucket(default) in the passwd file."  In-container cleanup (rm, sort -u)
cannot reach the orchestration-layer file.

Replace mountBucket() with direct s3fs mounting inside the container,
following the pattern from the Cloudflare Containers FUSE-mount docs:

1. Write credentials to /etc/passwd-s3fs via startProcess (overwrite, not
   append — always exactly one entry)
2. Run s3fs directly inside the container
3. Verify the mount succeeded

Credentials are passed via process env vars (R2_KEY, R2_SECRET) to avoid
embedding secrets in the command string.

The in-flight promise lock is retained to coalesce concurrent callers
within the same Worker isolate.

https://claude.ai/code/session_01E5t9gPHDGGrTUWeagkDjVo
@piffie piffie force-pushed the claude/fix-r2-mount-error-SrDsd branch from 01e14d3 to 8f324b3 Compare February 8, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants