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

Removed race condition from global_queue_depth_multi_thread test #6936

Merged

Conversation

jofas
Copy link
Contributor

@jofas jofas commented Oct 25, 2024

@Darksonn and @mox692 discovered a race condition in the retry logic introduced in #6916 that this PR aims to fix.

In the global_queue_depth_multi_thread test, we try to block the two worker threads before spawning more tasks onto the global queue. This allows us to measure the RuntimeMetrics::global_queue_depth deterministically, as the two worker threads are blocked and therefore unable to pull any tasks from the global queue. Blocking the two worker threads might fail, in which case one of the tasks from the previous try to block the runtime would remain in the global queue. If the task remains in the global queue after the second try to block the runtime succeeds, it would add an unexpected task to the global_queue_depth, making the test fail.

The solution this PR provides is to just create a new runtime on each try to block it. So if the first try to block the runtime fails, we drop the runtime and create a new one (with an empty global queue) that we then try to block again. We proceed until we succeed in blocking one runtime or run out of tries.

@@ -93,7 +93,7 @@ fn try_block_threaded(rt: &Runtime) -> Result<Vec<mpsc::Sender<()>>, mpsc::RecvT

// Spawn a task per runtime worker to block it.
rt.spawn(async move {
tx.send(()).unwrap();
tx.send(()).ok();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made this fail silently because I triggered a panic here when I ^Ced a test run, which I found needlessly confusing.

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-runtime Module: tokio/runtime M-metrics Module: tokio/runtime/metrics and removed M-runtime Module: tokio/runtime labels Oct 25, 2024
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Thanks.

Copy link
Member

@mox692 mox692 left a comment

Choose a reason for hiding this comment

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

I think merging the master branch would make the ci happy!

@jofas jofas force-pushed the fix-flaky-injection-queue-test-revisited branch from 8235535 to 78f7009 Compare October 27, 2024 14:21
@jofas
Copy link
Contributor Author

jofas commented Oct 27, 2024

Thanks for the heads up, didn't see that the CI failure was fixed.

@Darksonn Darksonn merged commit 070a825 into tokio-rs:master Oct 27, 2024
81 checks passed
@jofas jofas deleted the fix-flaky-injection-queue-test-revisited branch October 27, 2024 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-metrics Module: tokio/runtime/metrics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants