fix(cli): Add retry logic for executable copy to handle EPERM race condition#5278
Open
ThomasSteinbach wants to merge 1 commit intoDioxusLabs:mainfrom
Open
fix(cli): Add retry logic for executable copy to handle EPERM race condition#5278ThomasSteinbach wants to merge 1 commit intoDioxusLabs:mainfrom
ThomasSteinbach wants to merge 1 commit intoDioxusLabs:mainfrom
Conversation
…ndition Fixes DioxusLabs#5275 When dx serve copies the compiled executable, cargo may not have fully released file handles yet. This causes intermittent EPERM errors with 20-90% failure rate depending on system load. Solution: Retry with exponential backoff (20ms, 40ms, 80ms, 160ms, 320ms) - Only retries on EPERM (errno 1) - Max 5 attempts - Logs warnings when retries occur - Verified 0% failure rate in stress testing (20/20 builds)
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.
Problem
Fixes #5275
Fixes #5256
When running
dx serveordx build, the CLI intermittently fails with:This occurs at the file copy step after cargo completes compilation. The root cause is a race condition where cargo has finished building but hasn't fully released OS-level file handles to the executable yet.
Failure rate: 20-90% depending on system load and build frequency
Affected platforms: Primarily macOS, potentially other Unix systems
Impact: Blocks development workflow, requires repeated manual retries
Root Cause
The error occurs in
write_executable()at thestd::fs::copy()call:Timing window: When this copy happens 0-200ms after cargo exits, the OS may still be releasing file locks/handles. This produces EPERM (error code 1).
Solution
Add retry logic with exponential backoff specifically for EPERM errors:
Testing
Before fix: 20-90% failure rate in stress testing
After fix: 0% failure rate in 20+ consecutive builds
The fix has been verified with:
rm -rf target/dx && dx build)dx serve)Changes
Durationto imports inpackages/cli/src/build/request.rsstd::fs::copy()call with retry loop handling EPERMAlternative Approaches Considered
The retry approach is simple, robust, and has minimal performance impact.