Skip to content

Ensure test library issues json string line-by-line#109729

Merged
bors merged 1 commit intorust-lang:masterfrom
fortanix:raoul/bugfix_libtest_json_synchronization
May 3, 2023
Merged

Ensure test library issues json string line-by-line#109729
bors merged 1 commit intorust-lang:masterfrom
fortanix:raoul/bugfix_libtest_json_synchronization

Conversation

@raoulstrackx
Copy link
Contributor

#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.

(#109484 implemented a partial fix for this issue; it only avoids that failed json parsing would result in a panic.)

cc: @jethrogb, @pietroalbini

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants