From owner-freebsd-threads@FreeBSD.ORG Sun Aug 15 17:04:07 2004 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D55A616A4D1 for ; Sun, 15 Aug 2004 17:04:07 +0000 (GMT) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8F26943D1F for ; Sun, 15 Aug 2004 17:04:07 +0000 (GMT) (envelope-from robert@fledge.watson.org) Received: from fledge.watson.org (localhost [127.0.0.1]) by fledge.watson.org (8.12.11/8.12.11) with ESMTP id i7FH2KOl061958 for ; Sun, 15 Aug 2004 13:02:20 -0400 (EDT) (envelope-from robert@fledge.watson.org) Received: from localhost (robert@localhost)i7FH2KGr061955 for ; Sun, 15 Aug 2004 13:02:20 -0400 (EDT) (envelope-from robert@fledge.watson.org) Date: Sun, 15 Aug 2004 13:02:20 -0400 (EDT) From: Robert Watson X-Sender: robert@fledge.watson.org To: threads@FreeBSD.org Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: thread-unsafe syslog code in libc? X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Aug 2004 17:04:08 -0000 I recently resolved a kernel race reported by Martin Blapp in which a file descriptor had connect() called on it by one thread, and was simultaenously close()'d by another. The bug resulted in a kernel crash, which is certainly not the right response, and I'm working on a number of aspects of that problem. However, this also speaks to a race in user space. The socket in question was being connected to /var/run/log, so I believe it was made from the libc syslog code. A glance at src/lib/libc/gen/syslog.c suggests that things are indeed a bit un-threadsafe, especially in vsyslog(), where things get connected and disconnected a fair amount. I'm guessing we need some sort of synchronization around use of that file descriptor to prevent this sort of race from happening in the future, as potentially it might lose log records, etc. It's also doing a lot of work by reconnecting so frequently, and I have to wonder if we can't improve the performance of applications using syslog by doing a better job at using a single connection... Robert N M Watson FreeBSD Core Team, TrustedBSD Projects robert@fledge.watson.org Principal Research Scientist, McAfee Research