roc-streaming / roc-toolkit

Real-time audio streaming over the network.
https://roc-streaming.org
Mozilla Public License 2.0
1.06k stars 213 forks source link

Fix potential deadlock in async_close() #331

Closed gavv closed 4 years ago

gavv commented 4 years ago

In the previois implementation, async_close() was allowed to invoke handle_close() in place. async_close() is always called under a mutex. handle_close() acquires the mutex too, resulting in a deadlock.

The problem didn't appear in practice because the circumstances when handle_close() is called in place are very rare: uv_udp_init() should fail to make it happen, or double async_close() call should happen.

In the new implementation, instead of calling handle_close() in place, async_close() returns false instead, which means that there is no need to wait for handle_close() call.