Skip to content

fix(envd): return error when concurrent /init races on NFS mount - #3460

Open
AdaAibaby wants to merge 1 commit into
e2b-dev:mainfrom
AdaAibaby:fix/envd-nfs-concurrent-init-v2
Open

fix(envd): return error when concurrent /init races on NFS mount#3460
AdaAibaby wants to merge 1 commit into
e2b-dev:mainfrom
AdaAibaby:fix/envd-nfs-concurrent-init-v2

Conversation

@AdaAibaby

@AdaAibaby AdaAibaby commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

When two concurrent /init requests race on isMountingNFS, the CompareAndSwap guard in setupNFS returns the named error value e, which is nil. The second caller proceeds as if NFS mounted successfully — sandbox starts with no volume mounts and no error surfaced to the caller.

Fix: return a package-level sentinel ErrConcurrentNFSInit so the caller receives a 500 and can retry. Using a sentinel (rather than fmt.Errorf) allows callers to match the error with errors.Is(), consistent with ErrAccessTokenMismatch and other sentinels in the same file.

Change

// before
if !a.isMountingNFS.CompareAndSwap(false, true) {
    logger.Debug().Msg("NFS volumes already mounting")
    return e  // nil — silent failure
}

// after
var ErrConcurrentNFSInit = errors.New("NFS mount already in progress")

if !a.isMountingNFS.CompareAndSwap(false, true) {
    logger.Debug().Msg("NFS volumes already mounting")
    return ErrConcurrentNFSInit
}

1 file, 2 lines changed.

/cc @jakubno @dobrac @ValentaTomas @arkamar @tvi Looking forward to your code review.

setupNFS guards against concurrent callers with an atomic CAS, but on
contention it returned nil (the named return zero value). The second
caller then continued as if NFS was mounted, so the sandbox started
with missing volume mounts and no indication of failure.

Return an explicit error so the caller receives a 500 and can retry,
rather than silently succeeding with no mount.
@AdaAibaby
AdaAibaby force-pushed the fix/envd-nfs-concurrent-init-v2 branch from 37b9c37 to dbaa103 Compare July 30, 2026 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants