ust_fd close() causes deadlock for any multithreaded application
I discovered today an even more serious problem with the current implementation of close/flose().
It does not neither handle the thread cancellation nor make the mutex robustness.
Which means if any of the thread of a multiple threads application got cancelled during calling close()/fclose(), the cancelled thread will terminated leaving the mutex at a persistent lock state.
Any call of close()/fclose() later at any other thread will be blocked forever.
What makes this really serious is because the scenario is quite simple, just thread cancellation during close then it block all other close() forever.
We need to either:
- Disable the thread cancellation at start of lttng_ust_safe_close_fd and re-enable it later.
- Setup the thread cancellation handler and do the mutex if needed.
- Set the mutex as PTHREAD_MUTEX_ROBUST, then check for return code and do pthread_mutex_consistent when needed.