Replies: 1 comment 1 reply
-
When the Runtime is shut down, all tasks are killed. Attached vs detached makes no difference. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I made a JobQueue that is supposed to run jobs in serialized fashion, one at a time.
Internally it spawns two sub-tasks, and when a new job is added via JobQueue::add_job() a message is sent over an mpsc channel to a sub-task.
Everything works great except that under certain conditions during runtime shutdown the add_job() method gets called by a long-running application task (external to job-queue) and somehow the channel send() fails with a "channel closed" SendError.
This is a bit surprising to me because JobQueue has not yet been dropped and is still holding JoinHandle for the two sub-tasks in a TaskTracker, so they are not detached.
My questions are:
I read the tokio docs carefully but they are unclear on if attached tasks are handled differently from detached tasks during shutdown, and what the ordering is, if any. My (naive?) expectation would be that the primary tokio task would be aborted, and its cleanup would eventually drop my JobQueue, which would detach its sub-tasks, which would then be aborted by the runtime.
I have a fully documented playground here with JobQueue and a unit test that demonstrates the issue.
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d888dff82b5940950e1ae2b862592249
Beta Was this translation helpful? Give feedback.
All reactions