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
Don't auto-advance time when a spawn_blocking task is running. #5115
Commits on Nov 16, 2022
-
Don't auto-advance time when a spawn_blocking task is running.
Time shouldn't auto-advance unless there's really nothing else going on. In general that is hard to fix, but this special case is relatively easy. Fixes: tokio-rs#4614
-
spawn_blocking: Re-enable auto-advance if the task panics.
This uses a destructor, so it will also work if tokio machinery panics while trying to e.g. spawn a thread.
-
-
-
-
-
Attempt to fix race condition with blocking tasks and paused time.
The auto-advance inhibit count must be decremented after the blocking task is finished, and crucially after waking the JoinHandle, to prevent the tokio thread from auto-advancing before tasks awaiting that JoinHandle are rescheduled.
-
-
-
Fix race when main thread is parked as auto-advance is re-enabled.
Specifically, when a blocking task is spawned, but no thread immediately awaits the JoinHandle, if the main thread parks itself, we previously failed to unpark it when the blocking task completed. Auto-advance would be re-enabled but could not happen, a potential deadlock.
-
-
-
BlockingSchedule::new: Avoid calling Handle::current().
It does not always work; and is it happens, the caller has a handle already and can just pass it in.
-