Fix test yield_calls_park_before_scheduling_again
#6536
Labels
A-tokio
Area: The main tokio crate
E-help-wanted
Call for participation: Help is requested to fix this issue.
E-medium
Call for participation: Experience needed to fix: Medium / intermediate
M-runtime
Module: tokio/runtime
If you run the following command from the tokio subdirectory:
then this test will fail:
tokio/tokio/src/runtime/tests/loom_multi_thread/yield_now.rs
Lines 5 to 30 in f6eb1ee
then the
assert_eq!(park_count + 1, new_park_count)
assertion will fail like this:This test should be fixed.
Details on why the test fails:
The
yield_now
function uses a special defer queue to make sure that the task that is usingyield_now
doesn't get polled again until we have checked the IO/timer drivers for new IO or timer events. This ensures that IO and timer events are given higher priority than theyield_now
task. Behind the scenes, the IO and timer drivers are checked by calling thepark_timeout
function with a timeout of zero. The test in question verifies that the IO/timer drivers are actually checked before the task gets scheduled again.The test is able to detect whether parking has happened using this counter:
tokio/tokio/src/runtime/park.rs
Lines 35 to 39 in f6eb1ee
However, there is one situation where the runtime attempts to park, but is unable to actually do so:
tokio/tokio/src/runtime/scheduler/multi_thread/park.rs
Lines 70 to 77 in f6eb1ee
Basically, the call to
try_lock
fails if a different worker thread is also callingpark_timeout
at the same time. In that case, the current thread doesn't actually perform the park operation, since there is another thread that will take care of IO/timer events for us.To fix this we, need to increment the
CURRENT_THREAD_PARK_COUNT
counter even iftry_lock
fails.The text was updated successfully, but these errors were encountered: