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

Immediately drop new task when runtime is shut down #3752

Merged
merged 9 commits into from May 26, 2021

Conversation

Darksonn
Copy link
Contributor

@Darksonn Darksonn commented May 5, 2021

Attempt to resolve #3548 by having each runtime's spawn method drop the new task.

I was only able to get it to work for the basic scheduler.

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-runtime Module: tokio/runtime labels May 5, 2021
@Darksonn Darksonn requested a review from carllerche May 5, 2021 12:30
@carllerche
Copy link
Member

Looks related to: #3708

}
}
}
drop(remote_queue);
Copy link
Member

Choose a reason for hiding this comment

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

If the drop here is significant (which it probably is because this is a lock guard), it probably is worth adding a comment saying so to avoid removing it in the future by accident.

Copy link
Member

Choose a reason for hiding this comment

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

Does the drop here in interact with the assert below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I only put it in to make it more visually clear where the lock is dropped.

@@ -429,7 +436,9 @@ impl Schedule for Arc<Shared> {
// safety: the task is inserted in the list in `bind`.
unsafe { cx.tasks.borrow_mut().owned.remove(ptr) }
} else {
self.queue.lock().push_back(Entry::Release(ptr));
if let Some(queue) = self.queue.lock().as_mut() {
Copy link
Member

Choose a reason for hiding this comment

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

So what happens if this is None? Will the task leak?

Copy link
Member

Choose a reason for hiding this comment

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

After digging in, this looks fine, a comment explaining why would be nice.

Comment on lines +402 to +409
let jh1 = handle.spawn(futures::future::pending::<()>());

drop(rt);

let jh2 = handle.spawn(futures::future::pending::<()>());

let err1 = jh1.now_or_never().unwrap().unwrap_err();
let err2 = jh2.now_or_never().unwrap().unwrap_err();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@carllerche The unwrap() on err1 here sometimes fails with the threaded scheduler. Isn't the drop call supposed to wait until the runtime is fully shut down?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is fixed by the "Fix loom test" commit

@Darksonn Darksonn marked this pull request as ready for review May 19, 2021 15:42
Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

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

Thanks 👍 this looks good to me. There are a couple of comments inline that have requests for comments, but the change looks correct.

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-runtime Module: tokio/runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rt: Handle::spawn should return an error that the runtime has gone away
3 participants