Date: Tue, 28 Sep 2004 22:30:28 GMT From: Dan Nelson <dnelson@allantgroup.com> To: freebsd-java@FreeBSD.org Subject: Re: java/72151: JVM crash on 5.2.1-R Message-ID: <200409282230.i8SMUSd2020092@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR java/72151; it has been noted by GNATS. From: Dan Nelson <dnelson@allantgroup.com> To: Andrzej Bialecki <ab@getopt.org> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200409282230.i8SMUSd2020092>