From owner-freebsd-java@FreeBSD.ORG Tue Sep 28 22:30:28 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 DC2B216A4CE for ; Tue, 28 Sep 2004 22:30:28 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id CC96F43D54 for ; Tue, 28 Sep 2004 22:30:28 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i8SMUSQ1020093 for ; Tue, 28 Sep 2004 22:30:28 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i8SMUSd2020092; Tue, 28 Sep 2004 22:30:28 GMT (envelope-from gnats) Date: Tue, 28 Sep 2004 22:30:28 GMT Message-Id: <200409282230.i8SMUSd2020092@freefall.freebsd.org> To: freebsd-java@FreeBSD.org From: Dan Nelson Subject: Re: java/72151: JVM crash on 5.2.1-R X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Dan Nelson List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Sep 2004 22:30:29 -0000 The following reply was made to PR java/72151; it has been noted by GNATS. From: Dan Nelson To: Andrzej Bialecki Cc: freebsd-gnats-submit@FreeBSD.org Subject: Re: java/72151: JVM crash on 5.2.1-R Date: Tue, 28 Sep 2004 17:21:58 -0500 In the last episode (Sep 28), Andrzej Bialecki said: > Running an application for Internet search engine (www.nutch.org). JDK built from ports: > > # java -version > java version "1.4.2-p6" > Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-p6-root_21_sep_2004_22_20) > Java HotSpot(TM) Client VM (build 1.4.2-p6-root_21_sep_2004_22_20, mixed mode) > > When executing a multi-threaded crawl (~50 threads), and running it for a couple of hours, JVM crashes with the following error log: > > An unexpected exception has been detected in native code outside the VM. > Unexpected Signal : 11 occurred at PC=0x28151624 > Function=flockfile+0x24 > Library=/lib/libc.so.5 > > Current Java thread: > at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) This is because java is calling gethostent() which is not thread-safe (POSIX does not require it to be, either). It uses a global "hostf" FILE* to read /etc/hosts, so multiple threads doing DNS lookups will almost certainly trash each other. My quick hack is this, which returns a DNS error if hostf ends up NULL. A better fix would be to add a mutex around the DNS routines in Inet4AddressImpl.lookupAllHostAddr. Index: gethostbyht.c =================================================================== RCS file: /home/ncvs/src/lib/libc/net/gethostbyht.c,v retrieving revision 1.16 diff -u -p -r1.16 gethostbyht.c --- gethostbyht.c 22 Mar 2002 21:52:29 -0000 1.16 +++ gethostbyht.c 3 Aug 2004 16:43:02 -0000 @@ -112,6 +112,10 @@ gethostent() return (NULL); } again: + if (!hostf) { + h_errno = NETDB_INTERNAL; + return (NULL); + } if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) { h_errno = HOST_NOT_FOUND; return (NULL); -- Dan Nelson dnelson@allantgroup.com