Bugfix: avoid panic on invalid json output from libtest by raoulstrackx · Pull Request #109484 · rust-lang/rust

@rustbot rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

T-bootstrap

Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

labels

Mar 22, 2023

@raoulstrackx

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Mar 24, 2023

bors added a commit to rust-lang-ci/rust that referenced this pull request

Mar 25, 2023
…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

bors added a commit to rust-lang-ci/rust that referenced this pull request

May 2, 2023
…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`