mozilla / audioipc

Cubeb Audio Remoting For Gecko
10 stars 17 forks source link

audioipc: Avoid calling poll_complete when dropped outside task context. #102

Closed kinetiknz closed 4 years ago

kinetiknz commented 4 years ago

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.

Addresses BMO 1644227.

r? @ChunMinChang please