wolfcw / libfaketime

libfaketime modifies the system time for a single application
https://github.com/wolfcw/libfaketime
GNU General Public License v2.0
2.71k stars 325 forks source link

deadlock in clock_gettime, when it calls pthread_mutex_lock #331

Closed v-gb closed 3 years ago

v-gb commented 3 years ago

Given a multithreaded program running under libfaketime, I have observed a fork from that program get stuck in clock_gettime's faketime wrapper, waiting for this pthread_mutex_lock from the "MT" version of the .so. clock_gettime is async signal safe, so in principle, it is legal to call it after forking a multithreaded program, but pthread_mutex_lock is not correct in that context.

I'm not exactly sure what this lock is supposed to help with, but maybe the locking should only be done when FAKETIME=something-that-requires-locks? I use fixed offsets, FAKETIME=+123d, and it seems that the lock should not be needed in this case.

v-gb commented 3 years ago

The problem still exists, but at least with #344, it's possible to opt-out of behaviors that could be problematic, so I'm going to call this good enough.