syslog() thread unsafety

Eugene Grosbein eugen at
Wed Jun 14 13:49:47 UTC 2017


Our [v]syslog() implementation in src/lib/libc/gen/syslog.c
tries to be thread-safe and uses "syslog_mutex".

It may lock this mutex then call blocking system calls like sendto().
If a thread owning this mutex is pthread_cancel()'d in process,
the mutex stays UMUTEX_CONTESTED and every other thread calling [v]syslog() deadlocks.

I can reproduce this with net/mpd5 daemon reliably within some seconds
from the beginning of my stress test involving RADIUS so mpd5 runs multi-threaded.

I've tried to wrap every mpd5's [v]syslog() call around with
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate) and
pthread_setcancelstate(oldstate, NULL) statements and this eliminates the problem
but that's not a solution in any way.

This problem seems to be root cause of multiple complaints
about mpd5 being unstable under FreeBSD 9.x+ version (PR: 186114, 214482).

Please take a look.

Eugene Grosbein

More information about the freebsd-stable mailing list