-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chan_console: Fix deadlock caused by unclean thread exit. #309
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
chan_console: Fix deadlock caused by unclean thread exit. #309
Conversation
cherry-pick-to: 18 |
To terminate a console channel, stop_stream causes pthread_cancel to make stream_monitor exit. However, commit 5b8fea9 added locking to this function which results in deadlock due to the stream_monitor thread being killed while it's holding the pvt lock. To resolve this, a flag is now set and read to indicate abort, so the use of pthread_cancel and pthread_kill can be avoided altogether. Resolves: asterisk#308
3d74796
to
2b04837
Compare
Isn’t this what |
Maybe cleaner than setting the cancellability, but it's a little messy and using I restored the |
And why is that? |
Because the thread that's cancelled doesn't get to control how it exits. You can add a cleanup handler but now you'd probably need to keep track of whether it's holding a mutex, for example, and then release it only then. This guy here has a good explanation that says it better than I can: https://stackoverflow.com/a/3438576
|
Is |
Internally, probably (internally, I imagine it would call |
Of course it does. |
Yes, but if I believe by default all threads are cancellable so without this there isn't a guarantee it won't be cancelled in the middle. I originally tested it this way before changing it to a flag. This should also work, if you strongly prefer this approach to setting a flag and not using |
My preference would be to use cancellation but I am not writing the code. If you've confirmed this fixes the issue then it's fine. |
Successfully merged to branch master and cherry-picked to ["18","20","21"] |
To terminate a console channel, stop_stream causes pthread_cancel to make stream_monitor exit. However, commit 5b8fea9 added locking to this function which results in deadlock due to the stream_monitor thread being killed while it's holding the pvt lock.
To resolve this, a flag is now set and read to indicate abort, so the use of pthread_cancel and pthread_kill can be avoided altogether.
Resolves: #308