Date: Fri, 19 Mar 2004 21:29:40 -0800 (PST) From: Pavlin Radoslavov <pavlin@icir.org> To: freebsd-gnats-submit@FreeBSD.org Subject: java/64492: NetworkInterface.getNetworkInterfaces() leaks file descriptors Message-ID: <200403200529.i2K5TeSr099312@www.freebsd.org> Resent-Message-ID: <200403200530.i2K5UNsK097273@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200403200529.i2K5TeSr099312>