-
Notifications
You must be signed in to change notification settings - Fork 571
Close non-stdio file handles when daemonizing #2314
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
base: main
Are you sure you want to change the base?
Conversation
The test if env::var("SCCACHE_ERROR_LOG").is_ok() {
let f = create_error_log()?;
// Can't report failure here, we're already daemonized.
daemonize()?;
redirect_error_log(f)?; That code was opening a log file, daemonizing, then swapping stderr with it. We could pass the file descriptor of I'm updating the patch to make daemonize accept a log file as argument and do the file handle swap at that point, which also removes the need for the |
0fc0c5a
to
2c22e92
Compare
Several CI jobs are consistently failing, so probably there are still file handles unaccounted. Will have to reproduce the failures locally and find the missing handles. |
I checked the failures now and it seems it is just formatting nits and failures to build on Windows. If there was something more serious, I can't see it now... Oh well, I'm updating the patch with the formatting nits applied and with the |
2c22e92
to
c619955
Compare
Any thoughts on the patch? Can someone approve the CI workflows so they can run? |
sorry for the latency |
This is very odd because diff --git a/src/util.rs b/src/util.rs
index 7174681..04d348c 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -841,7 +841,7 @@ impl<'a> Hasher for HashToDigest<'a> {
/// Pipe `cmd`'s stdio to `/dev/null`, unless a specific env var is set.
#[cfg(not(windows))]
-pub fn daemonize() -> Result<()> {
+pub fn daemonize(log_file: Option<File>) -> Result<()> { It's as if the patch had been only partially applied by the CI server. The same error is happening in many of them. |
Oooooh, because they're the Windows builds! I keep forgetting the |
c619955
to
8406beb
Compare
/// Daemonizing is a no-op on Windows, but we still must set the log file as
/// stderr.
#[cfg(windows)]
pub fn daemonize(log_file: Option<File>) -> Result<()> {
if let Some(log_file) = log_file {
redirect_stderr(log_file);
}
Ok(())
} The failures of the let log_contents = fs::read_to_string(sccache_log)?;
assert!(predicates::str::contains("server has setup with ReadOnly").eval(log_contents.as_str())); Hopefully no more remaining failures! |
8406beb
to
5a3a6be
Compare
Hi @sylvestre, Is it ok for you now? |
Otherwise, when the compiler wrapper spawns the sccache server, the server may end up with unintended file descriptors, which can lead to unexpected problems. This is particularly problematic if any of those file descriptors that accidentally end up in the server process is a pipe, as the pipe will only be closed when all the processes with that file descriptor close it or exit. This was causing sccache to hang ninja, as ninja uses the EOF of a pipe given to the subprocess to detect when that subprocess has exited: ninja-build/ninja#2444 (comment) This patch adds a dependency on the [close_fds](https://crates.io/crates/close_fds) crate, which automatically chooses an appropriate mechanism to close a range of file descriptors. On Linux 5.9+ that mechanism will be libc::close_range(). Fixes mozilla#2313
5a3a6be
to
8125bae
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2314 +/- ##
==========================================
- Coverage 65.66% 65.63% -0.04%
==========================================
Files 65 65
Lines 35496 35531 +35
==========================================
+ Hits 23310 23321 +11
- Misses 12186 12210 +24 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Otherwise, when the compiler wrapper spawns the sccache server, the server may end up with unintended file descriptors, which can lead to unexpected problems.
This is particularly problematic if any of those file descriptors that accidentally end up in the server process is a pipe, as the pipe will only be closed when all the processes with that file descriptor close it or exit.
This was causing sccache to hang ninja, as ninja uses the EOF of a pipe given to the subprocess to detect when that subprocess has exited: ninja-build/ninja#2444 (comment)
This patch adds a dependency on the
close_fds crate, which automatically chooses an appropriate mechanism to close a range of file descriptors. On Linux 5.9+ that mechanism will be libc::close_range().
Fixes #2313