-
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
cargo test occasionally leaves a file descriptor open when exec'ing a binary on Mac #6344
Comments
This is likely an unfortunate inevitability because OSX doesn't have atomic open-and-set-CLOEXEC APIs, meaning we're fundamentally always capable of leaking fds to child processes |
Is that still true? 10 minutes ago I didn't know what CLOEXEC was, but it looks like it's available in modern macOS? The answers in https://stackoverflow.com/q/1309521/463761 seem to be happily talking about calling |
@dwijnand Specifically @alexcrichton is referring to atomic open-and-set-CLOEXEC, rather than just set-CLOEXEC. For example, whereas on linux and many other unices Ths issue is that if a fork occurs on thread A, while thread B is midway between these two calls, then a fd is leaked into the fork without @alexcrichton There are workarounds, e.g. performing the two calls in a fork and sending the fd back to the main process over a |
TIL. Thank you. |
@alecmocatta heh unfortunately we'd have to do that in the standard library so that may be a bit difficult to stomach at this point unfortunately :( Note though that the window for this multithreaded problem is quite small so in theory it shouldn't happen all that much. If a file descriptor is deterministically leaked into the child on OSX that probably means we have an actual problem which we should fix as well! |
Problem
cargo test
occasionally leaves a file descriptor open whenexec
ing a binary.Steps
The following as a test with
harness = false
in the Cargo.toml:sometimes balks on Mac, specifically at fd
6
, which if you try to open it withFile::open("/dev/fd/6")
is most of the time successful but sometimes returnsErrorKind::PermissionDenied
akaEPERM
.Notes
Witnessed on nightlies for the last ~4 months.
I see this on travis (at least on macos-10.13-xcode9.4.1) running this test occasionally but haven't observed locally. Will update if/when I have more details; documenting in case anyone else observes in the meantime.
The text was updated successfully, but these errors were encountered: