-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access Denied Error (os error 5) if testing while the main program is running. #12485
Comments
This comment was marked as outdated.
This comment was marked as outdated.
Thanks for the report! I have moved this to the cargo repo. Unfortunately I'm unable to reproduce with the given instructions. Can you please share a full project that exhibits the problem, including the |
I'm assuming that this is windows specific behavior where you can't overwrite a file that is in use. In this case, so long as the binary from I'm assuming cargo will only overwrite the main binary if something has changed. Any other operations that are happening might be important when preparing more detailed reproduction steps. |
I can reproduce the problem on win11. The environment is the same as I mentioned in the issue, and here attaches the full code. |
If this is the case, here are two issues you may be interested in: |
Looking at the attached project, it looks like the dev-dependencies introduce new features in shared dependencies which cause the binary to be rebuilt. That is tracked in #11954. If you want to avoid those rebuilds, one of the only options is to manually specify the dependencies (with Another suggestion is to avoid the workflow of having a test expecting to have a server running via My only suggestion is for cargo to provide a better error message for "Access Denied" when trying to remove an executable, and provide a suggestion to check if the executable is currently running, and explain that it cannot be replaced in that scenario. I can't exactly reproduce the given error here, since on my system the linker fails first with a very different error. |
Thanks! I will try those methods and waiting for better error messages from cargo. |
I encountered the same issue. A workaround is to specify a different directory from the default target using the |
Following up from #14757 (comment) where I suggested killing the process.
That makes sense. Maybe it would be nice to prompt for X seconds asking if the user wants to kill the process if it's executing in a tty? It would be a nice quality of life improvement. Running into this can sometimes cost me a few minutes of time if doing a release build. |
I tried these simple code. But if I run
cargo run
,and then runcargo test
in another terminal, it always shows:error: failed to remove file 'C:\my\Tut\rust_nails\target\debug\rust_nails.exe' Caused by: Access Denied. (os error 5)
main.rs code:
Test code:
I expected to see this happen: Test should be able to run while the program is running.
Instead, this happened: Testing code failed to execute with OS Error 5.
Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: