From owner-freebsd-java@FreeBSD.ORG Fri Mar 19 21:30:23 2004 Return-Path: Delivered-To: freebsd-java@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 591EE16A4CF for ; Fri, 19 Mar 2004 21:30:23 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 39C1243D2F for ; Fri, 19 Mar 2004 21:30:23 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i2K5UNbv097274 for ; Fri, 19 Mar 2004 21:30:23 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.10/8.12.10/Submit) id i2K5UNsK097273; Fri, 19 Mar 2004 21:30:23 -0800 (PST) (envelope-from gnats) Resent-Date: Fri, 19 Mar 2004 21:30:23 -0800 (PST) Resent-Message-Id: <200403200530.i2K5UNsK097273@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-java@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Pavlin Radoslavov Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0211316A4CE for ; Fri, 19 Mar 2004 21:29:41 -0800 (PST) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id D744943D2F for ; Fri, 19 Mar 2004 21:29:40 -0800 (PST) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.12.10/8.12.10) with ESMTP id i2K5Te72099313 for ; Fri, 19 Mar 2004 21:29:40 -0800 (PST) (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.12.10/8.12.10/Submit) id i2K5TeSr099312; Fri, 19 Mar 2004 21:29:40 -0800 (PST) (envelope-from nobody) Message-Id: <200403200529.i2K5TeSr099312@www.freebsd.org> Date: Fri, 19 Mar 2004 21:29:40 -0800 (PST) From: Pavlin Radoslavov To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Subject: java/64492: NetworkInterface.getNetworkInterfaces() leaks file descriptors X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Mar 2004 05:30:23 -0000 >Number: 64492 >Category: java >Synopsis: NetworkInterface.getNetworkInterfaces() leaks file descriptors >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-java >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Mar 19 21:30:22 PST 2004 >Closed-Date: >Last-Modified: >Originator: Pavlin Radoslavov >Release: 4.8-RELEASE >Organization: ICSI >Environment: FreeBSD xorp8.icir.org 4.8-RELEASE FreeBSD 4.8-RELEASE #0: Wed May 28 11:19:23 PDT 2003 root@xorp8.icir.org:/usr/src/sys/compile/XORP8-4.8 i386 >Description: Every time NetworkInterface.getNetworkInterfaces() is called on a system with IPv6 enabled it leaks a file descriptor (UDP socket). This is on a system with lastest port collection with jdk14 and with the lastest jdk14 patches (bsd-jdk14-patches-6.tar.gz) >How-To-Repeat: Write a simple program that repeatedly calls NetworkInterface.getNetworkInterfaces() Run the program and then in parallel list the number of open UDP socket. E.g.: lsof | egrep java | egrep UDP The output should be a growing list of opened UDP sockets COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME .. java 35251 pavlin 8u IPv4 0xddf80a00 0t0 UDP *:* java 35251 pavlin 9u IPv4 0xddf80ac0 0t0 UDP *:* java 35251 pavlin 10u IPv4 0xddf80b80 0t0 UDP *:* java 35251 pavlin 11u IPv4 0xddf80c40 0t0 UDP *:* java 35251 pavlin 12u IPv4 0xddf80d00 0t0 UDP *:* java 35251 pavlin 13u IPv4 0xddf80dc0 0t0 UDP *:* .. >Fix: The problem can be traced down to the BSD-specific patch applied by bsd-jdk14-patches-6.tar.gz More specifically, in the BSD iplementation of enumIPv4Interfaces() inside /usr/ports/java/jdk14/work/j2se/src/solaris/native/java/net/NetworkInterface.c Every time this function is called it leaks a file descriptor if IPv6 is enabled: first an IPv4 SOCK_DGRAM socket is opened, but then variable "sock" is reasigned to an IPv6 socket without closing the IPv4 socket. The simple patch below fixes the problem: --- work/j2se/src/solaris/native/java/net/NetworkInterface.c.leak Wed Feb 25 14:19:21 2004 +++ work/j2se/src/solaris/native/java/net/NetworkInterface.c Fri Mar 19 20:17:33 2004 @@ -605,6 +605,7 @@ /* * Do this check early to avoid unnecessary work. */ + close(sock); /* XXX: close the IPv4 socket */ if (ipv6_available()) { sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0); if (sock < 0) { A better solution is to close "sock" soon after every time it is opened because it is not used for anything more than to verify that an IPv4/IPv6 socket can be opened. >Release-Note: >Audit-Trail: >Unformatted: