Skip to content
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

fix(cli): remove possible deadlock in test channel #22662

Merged
merged 2 commits into from Mar 5, 2024

Conversation

mmastrac
Copy link
Member

@mmastrac mmastrac commented Mar 1, 2024

The stderr stream could possibly starve the other bits of the output-redirecting event loop.

let Some(stream) = &mut self.read_opt else {
return;
Copy link
Member Author

@mmastrac mmastrac Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could lead to starvation as we just quietly returned "ready" and tokio could select us again.

@@ -253,7 +265,7 @@ impl TestEventSenderFactory {
loop {
tokio::select! {
_ = test_stdout.pipe(), if test_stdout.is_alive() => {},
_ = test_stderr.pipe(), if test_stdout.is_alive() => {},
_ = test_stderr.pipe(), if test_stderr.is_alive() => {},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This typo here meant that we were polling test_stderr in a hot loop if it finished, never getting to the sync receiver

@@ -377,7 +389,9 @@ impl TestEventSender {
let mutex = parking_lot::RawMutex::INIT;
mutex.lock();
self.sync_sender.send(SendMutex(&mutex as _))?;
mutex.lock();
if !mutex.try_lock_for(Duration::from_secs(30)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really clever solution, LGTM!

@mmastrac mmastrac merged commit 72d34a7 into denoland:main Mar 5, 2024
17 checks passed
littledivy pushed a commit that referenced this pull request Mar 8, 2024
The stderr stream could possibly starve the other bits of the
output-redirecting event loop.

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants