ServerHandler is being dropped inside Tokio via release_node as part of the internal runtime shutdown. When ServerHandler is dropped, we call Sink::close primarily for the side effect of closing the underlying I/O stream. The docs for Sink state that a panic may occur if "it is called outside the context of a future's task", which is what's happening here.
Tokio manages the futures task executor TLS for us, and it's not clear if it's a bug or intentional that the task drop is run outside the task context here.
In either case, we can use futures::task::is_in_task (added in futures 0.1.27) inside our Sink::close impl to avoid calling poll_complete in the situation where it'd panic.
ServerHandler
is being dropped inside Tokio viarelease_node
as part of the internal runtime shutdown. WhenServerHandler
is dropped, we callSink::close
primarily for the side effect of closing the underlying I/O stream. The docs forSink
state that a panic may occur if "it is called outside the context of a future's task", which is what's happening here. Tokio manages the futures task executor TLS for us, and it's not clear if it's a bug or intentional that the task drop is run outside the task context here.In either case, we can use
futures::task::is_in_task
(added in futures 0.1.27) inside ourSink::close
impl to avoid callingpoll_complete
in the situation where it'd panic.Addresses BMO 1644227.
r? @ChunMinChang please