-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Bugfix: avoid panic on invalid json output from libtest #109484
Bugfix: avoid panic on invalid json output from libtest #109484
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
0810f68
to
0d1a054
Compare
I don't fully understand the problem or the solution, but shouldn't the fix be to avoid any race conditions from occurring in the first place? |
Fixing the race condition does not fully fix the problem here. Any test output (e.g. with |
@bors r+ rollup
Agreed, that was a mistake on my end here, sorry about that!
So, I think here we should fix the race condition in libtest by potentially adding locking when emitting the messages. While #108659 exposes the problem to users of the Rust build system, the underlying problem of broken and overlapping JSON being emitted is a bug of libtest's |
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#109355 (Fix bad suggestion for clone/is_some in field init shorthand) - rust-lang#109484 (Bugfix: avoid panic on invalid json output from libtest) - rust-lang#109539 (Refactor `find_*_stability` functions) - rust-lang#109542 (rustdoc: clean up `storage.js`) - rust-lang#109545 (Deeply check well-formedness of return-position `impl Trait` in trait) - rust-lang#109568 (miri: fix raw pointer dyn receivers) - rust-lang#109570 (Add GUI test for "Auto-hide item methods' documentation" setting) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…ynchronization, r=pietroalbini Ensure test library issues json string line-by-line rust-lang#108659 introduces a custom test display implementation. It does so by using libtest to output json. The stdout is read line by line and parsed. The code trims the line read and checks whether it starts with a `{` and ends with a `}`. Unfortunately, there is a race condition in how json data is written to stdout. The `write_message` function calls `self.out.write_all` repeatedly to write a buffer that contains (partial) json data, or a new line. There is no lock around the `self.out.write_all` functions. Similarly, the `write_message` function itself is called with only partial json data. As these functions are called from concurrent threads, this may result in json data ending up on the same stdout line. This PR avoids this by buffering the complete json data before issuing a single `self.out.write_all`. (rust-lang#109484 implemented a partial fix for this issue; it only avoids that failed json parsing would result in a panic.) cc: `@jethrogb,` `@pietroalbini`
#108659 introduces a custom test display implementation. It does so by using libtest to output json. The stdout is read and parsed; The code trims the line read and checks whether it starts with a
{
and ends with a}
. If so, it concludes that it must be a json encodedMessage
. Unfortunately, this does not work in all cases:--nocapture
will never start and end lines with{
and}
characterswrite_message
statements. Where only the last one issues a\n
. This likely results in a race condition as we see multiple json outputs on the same line when running tests for thex86_64-fortanix-unknown-sgx
target:This PR implements a partial fix by being much more conservative of what it asserts is a valid json encoded
Message
. This prevents panics, but still does not resolve the race condition. A discussion is needed where this race condition comes from exactly and how it best can be avoided.cc: @jethrogb, @pietroalbini