Handle 'already in use' error when R2 bucket is already mounted#209
Open
AnandChowdhary wants to merge 2 commits intocloudflare:mainfrom
Open
Handle 'already in use' error when R2 bucket is already mounted#209AnandChowdhary wants to merge 2 commits intocloudflare:mainfrom
AnandChowdhary wants to merge 2 commits intocloudflare:mainfrom
Conversation
The isR2Mounted() check (which runs `mount | grep` inside the sandbox) is unreliable and can return false even when the bucket is already mounted. This causes mountBucket() to be called again on subsequent requests, throwing InvalidMountConfigError. Rather than relying solely on the unreliable mount check in the catch block, detect the "already in use" error message and treat it as a successful mount. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
syncToR2 only mounted R2 but never started the gateway. On a fresh container, openclaw onboard (which creates openclaw.json) only runs during gateway startup. If "Sync now" is triggered before any other route starts the gateway, the config file doesn't exist and sync fails with "no config file found". Call ensureMoltbotGateway before syncing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Feb 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two bugs in R2 mount/sync handling that cause errors on fresh deployments and subsequent requests:
1. Handle "already in use" error when R2 bucket is already mounted
isR2Mounted()runsmount | grep "s3fs on /data/moltbot"inside the sandbox to detect existing mounts, but this check is unreliable — it can returnfalseeven when the bucket is already mounted (due to process polling timing, the grep not matching, etc.)isR2Mounted()incorrectly returnsfalse,mountBucket()is called again, which throwsInvalidMountConfigError: Mount path "/data/moltbot" is already in use by bucket "moltbot-data"mount | grepcheck2. Ensure gateway is running before syncing to R2
syncToR2only mounted R2 but never started the gatewayopenclaw onboard(which createsopenclaw.json) only runs during gateway startup viastart-openclaw.shensureMoltbotGateway()call before syncingChanges
src/gateway/r2.ts: Added early return in catch block when error contains "already in use"src/gateway/r2.test.ts: Added test case for theInvalidMountConfigErrorscenariosrc/gateway/sync.ts: AddedensureMoltbotGateway()call before sync, import from./processsrc/gateway/sync.test.ts: Added mock forensureMoltbotGatewayTest plan
mountR2StoragereturnstruewhenmountBucketthrows "already in use"syncToR2tests pass with mockedensureMoltbotGateway🤖 Generated with Claude Code