Description
TLDR: Should we run some flaky tests single-threaded? (Nope)
The build::close_output
test is randomly failing on CI. There were some fixes applied in #8286 in May 26, but there appears to be more recent failures:
rust-lang/rust#74312 (comment)
rust-lang/rust#74408 (comment)
rust-lang/rust#74908 (comment)
rust-lang/rust#74923 (https://github.com/rust-lang-ci/rust/runs/924743383)
The failure is:
---- build::close_output stdout ----
thread 'build::close_output' panicked at 'assertion failed: !status.success()', src/tools/cargo/tests/testsuite/build.rs:5016:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I am uncertain how this is possible, so maybe someone could double check that what I wrote makes sense. The test covers what happens when stdout or stderr is closed in the middle of the build. It uses a proc-macro as a sync point so that the test can know when compilation has started, and to emit data to stdout or stderr during the build. It should follow this sequence:
- Starts a TCP server.
- Starts the build.
- The proc-macro starts building.
- The proc-macro connects to the TCP server, and waits for the test to tell it it is OK to continue.
- Test receives connection from proc-macro
- Test closes stdout.
- Test tells proc-macro to continue.
- Proc-macro starts spewing stuff to stdout to cargo, which through the internal job queue ends up attempting to write to stdout. Since stdout was closed in step 6, this should fail.
- Cargo should exit with an error after rustc is done.
For some reason, at step 8, it successfully writes to stdout, and step 9 returns success.
I've been doing a few tests, and it gets worse based on the number of concurrent tests running. When run single threaded, I cannot get it to fail (even with the system under heavy load).
I'm feeling this is somewhat related to #7858. Is there still a race condition, even with atomic O_CLOEXEC? That is, AIUI, the file descriptors are still inherited across fork
, and only closed when exec
is called. If so, then there is a small window where the file descriptors have extra duplicates which prevent them from fully closing immediately.
I'm thinking a simple solution would be to isolate these tests into a separate test executable which runs with (Testing shows this probably won't fix this test.)--test-threads=1
(or maybe a simple no-harness test?). This should prevent concurrent tests from interfering with one another. The downside is that this makes it more cumbersome to run all of the test suite.