From owner-freebsd-bugs@FreeBSD.ORG Wed Oct 29 08:40:24 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EE50816A4CE for ; Wed, 29 Oct 2003 08:40:23 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id A0F0143FAF for ; Wed, 29 Oct 2003 08:40:20 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h9TGeKFY039828 for ; Wed, 29 Oct 2003 08:40:20 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h9TGeK3K039827; Wed, 29 Oct 2003 08:40:20 -0800 (PST) (envelope-from gnats) Resent-Date: Wed, 29 Oct 2003 08:40:20 -0800 (PST) Resent-Message-Id: <200310291640.h9TGeK3K039827@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jonathan Lennox Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 89A4716A4CE for ; Wed, 29 Oct 2003 08:31:49 -0800 (PST) Received: from cs.columbia.edu (cs.columbia.edu [128.59.16.20]) by mx1.FreeBSD.org (Postfix) with ESMTP id 07D6843FAF for ; Wed, 29 Oct 2003 08:31:48 -0800 (PST) (envelope-from lennox@cs.columbia.edu) Received: from cnr.cs.columbia.edu (cnr.cs.columbia.edu [128.59.19.133]) by cs.columbia.edu (8.12.10/8.12.10) with ESMTP id h9TGVkLa027604 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Wed, 29 Oct 2003 11:31:46 -0500 (EST) Received: from cnr.cs.columbia.edu (localhost [127.0.0.1]) by cnr.cs.columbia.edu (8.12.9p1/8.12.9) with ESMTP id h9TGVj2Y005482 for ; Wed, 29 Oct 2003 11:31:45 -0500 (EST) (envelope-from lennox@cnr.cs.columbia.edu) Received: (from lennox@localhost) by cnr.cs.columbia.edu (8.12.9p1/8.12.9/Submit) id h9TGVjLu005481; Wed, 29 Oct 2003 11:31:45 -0500 (EST) Message-Id: <200310291631.h9TGVjLu005481@cnr.cs.columbia.edu> Date: Wed, 29 Oct 2003 11:31:45 -0500 (EST) From: Jonathan Lennox To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/58687: gethostbyname leaks kqueue file descriptors with pthreads and static linking X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Jonathan Lennox List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Oct 2003 16:40:24 -0000 >Number: 58687 >Category: bin >Synopsis: gethostbyname leaks kqueue file descriptors with pthreads and static linking >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Oct 29 08:40:20 PST 2003 >Closed-Date: >Last-Modified: >Originator: Jonathan Lennox >Release: FreeBSD 5.1-RELEASE-p10 i386 >Organization: Columbia University >Environment: System: FreeBSD cnr.cs.columbia.edu 5.1-RELEASE-p10 FreeBSD 5.1-RELEASE-p10 #8: Sun Oct 5 23:47:09 EDT 2003 lennox@cnr.cs.columbia.edu:/usr/obj/usr/src/sys/CNR i386 The system has been patched by adding src/lib/libc_r/uthread/uthread_kqueue.c, aligning it with -CURRENT. (This is mp's patch of 2003-07-25.) >Description: When linking with a static libc_r and libc, gethostbyname() leaks kqueue file descriptors. (I actually first observed this with libc_r_p.a and libc_p.a, i.e. compiling and linking with -pg, but the same thing happens when linking with -static.) This is because &_kqueue isn't included in the 'references' array in uthread_init.c. There's no outstanding unresolved link to _kqueue when libc_r is linked in, so the linker only picks up the version from libc. See also closed PRs kern/55007 and bin/55879, which are this same problem with dynamic libraries, now fixed in -CURRENT and -STABLE. >How-To-Repeat: Compile the following program with static libc and libc_r, either with -static or -pg: ---------- #include #include #include void* the_thread(void* dummy) { int i; for (i = 0; i < 50; i++) { gethostbyname("www.freebsd.org"); } return NULL; } int main(void) { pthread_t dummy; pthread_create(&dummy, NULL, &the_thread, NULL); getchar(); return 0; } ---------- Before the program exits, use lsof to observe its open file descriptors. Notice that it has 50 KQUEUE descriptors open. In -CURRENT, this problem does not occur if you use dynamic libc and libc_r, though it does in 5.1-RELEASE. >Fix: Apply the following patch and rebuild: --- lib/libc_r/uthread/uthread_init.c.orig Wed Oct 29 11:00:53 2003 +++ lib/libc_r/uthread/uthread_init.c Wed Oct 29 11:01:21 2003 @@ -99,6 +99,7 @@ &_getsockopt, &_ioctl, &_kevent, + &_kqueue, &_listen, &_nanosleep, &_open, As a workaround: Add the command-line option -u kqueue (-Wl,-u,kqueue from gcc) when linking. >Release-Note: >Audit-Trail: >Unformatted: