From owner-freebsd-stable@freebsd.org Wed Jun 14 13:49:47 2017 Return-Path: Delivered-To: freebsd-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 36FA8D8E371 for ; Wed, 14 Jun 2017 13:49:47 +0000 (UTC) (envelope-from eugen@grosbein.net) Received: from hz.grosbein.net (hz.grosbein.net [78.47.246.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "hz.grosbein.net", Issuer "hz.grosbein.net" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id C290E3B8B; Wed, 14 Jun 2017 13:49:46 +0000 (UTC) (envelope-from eugen@grosbein.net) Received: from eg.sd.rdtc.ru (root@eg.sd.rdtc.ru [62.231.161.221]) by hz.grosbein.net (8.15.2/8.15.2) with ESMTPS id v5EDne0a089082 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Jun 2017 15:49:41 +0200 (CEST) (envelope-from eugen@grosbein.net) X-Envelope-From: eugen@grosbein.net X-Envelope-To: freebsd-stable@FreeBSD.org Received: from eg.sd.rdtc.ru (eugen@localhost [127.0.0.1]) by eg.sd.rdtc.ru (8.15.2/8.15.2) with ESMTP id v5EDnaVa093171; Wed, 14 Jun 2017 20:49:36 +0700 (+07) (envelope-from eugen@grosbein.net) To: FreeBSD Stable From: Eugene Grosbein Subject: syslog() thread unsafety X-Enigmail-Draft-Status: N1110 Cc: Gleb Smirnoff , Konstantin Belousov Message-ID: <59413EF0.20608@grosbein.net> Date: Wed, 14 Jun 2017 20:49:36 +0700 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=3.1 required=5.0 tests=BAYES_00, DATE_IN_FUTURE_96_Q, LOCAL_FROM autolearn=no autolearn_force=no version=3.4.1 X-Spam-Report: * 2.8 DATE_IN_FUTURE_96_Q Date: is 4 days to 4 months after Received: date * -2.3 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 2.6 LOCAL_FROM From my domains X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on hz.grosbein.net X-Spam-Level: *** X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Jun 2017 13:49:47 -0000 Hi! 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