From owner-freebsd-java@FreeBSD.ORG Mon Dec 11 15:25:23 2006 Return-Path: X-Original-To: freebsd-java@freebsd.org Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2821E16A40F for ; Mon, 11 Dec 2006 15:25:23 +0000 (UTC) (envelope-from achill@matrix.gatewaynet.com) Received: from matrix.gatewaynet.com (host2.dynacom.ondsl.gr [62.103.35.210]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3A95443CB3 for ; Mon, 11 Dec 2006 15:23:41 +0000 (GMT) (envelope-from achill@matrix.gatewaynet.com) Received: from host3.dynacom.ondsl.gr ([62.103.35.211] helo=ip216.internal.net) by matrix.gatewaynet.com with esmtp (Exim 4.62) (envelope-from ) id 1Gtn1L-0006Ai-BB for freebsd-java@freebsd.org; Mon, 11 Dec 2006 17:24:47 +0200 From: Achilleas Mantzios Organization: Dynacom Tankers Mgmt To: freebsd-java@freebsd.org Date: Mon, 11 Dec 2006 17:24:46 +0200 User-Agent: KMail/1.9.3 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-7" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200612111724.46716.achill@matrix.gatewaynet.com> Subject: Re: close() of active socket does not work on FreeBSD 6 X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Dec 2006 15:25:23 -0000 =D3=F4=E9=F2 =C4=E5=F5=F4=DD=F1=E1 11 =C4=E5=EA=DD=EC=E2=F1=E9=EF=F2 2006 1= 6:46, =EF/=E7 Arne H. Juul =DD=E3=F1=E1=F8=E5: > I've had problems with some tests hanging on FreeBSD 6/amd64. This happens > both with diablo-1.5.0_07-b01 and the java/jdk15 compiled from ports. > > After much digging we've determined that the root cause is that > the guarantee in the socket.close() API, see the documentation at > http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#close() > isn't fulfulled - the thread blocked in I/O on the socket doesn't wake up. > > Here's a pretty small test program that demonstrates the problem (given > that you're running sshd on port 22, if not change the port number to > something that the program can connect to). Is this a known problem? > Does it happen for everybody on FreeBSD 6? > In my systems, 1.4.2-p7, diablo-1.5.0_07-b00 have this problem. However with linux 1.4.2_12-b03 right after socket.close(), IOException is= =20 thrown and caught by the FooConn thread. > > > import java.io.*; > import java.net.*; > import java.util.*; > import java.util.logging.*; > > public class FooConn extends Thread { > private boolean alive; > public final int port; > private Socket socket =3D null; > > public FooConn(int port) { > super("FooConn:" + port); > this.port =3D port; > this.alive =3D true; > } > private void connect() { > while (socket =3D=3D null) { > try { > socket =3D new Socket("localhost", port); > } catch(IOException e) { > System.err.println("Connect failed: " + e); > try { Thread.sleep(1000); } catch(InterruptedException i= e) > {} > } > } > } > public void disconnect() throws IOException, InterruptedException { > alive =3D false; > System.out.println("closing socket"); > socket.close(); > System.out.println("calling join"); > join(); > } > public void run() { > while (alive) { > if (socket =3D=3D null) { > System.out.println("socket null, connect"); > connect(); > } > try { > int b =3D socket.getInputStream().read(); > System.out.println("got byte "+ b); > } catch (IOException e) { > System.out.println("IOException, set socket to null"); > socket =3D null; //triggers reconnect > } catch (RuntimeException e) { > System.err.println("RuntimeException "+e); > return; > } > } > } > public static void main(String[] args) throws IOException { > try { > FooConn conn =3D new FooConn(22); > conn.start(); > Thread.sleep(1000); > conn.disconnect(); > } catch(InterruptedException ie) {} > } > } > _______________________________________________ > freebsd-java@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-java > To unsubscribe, send any mail to "freebsd-java-unsubscribe@freebsd.org" =2D-=20 Achilleas Mantzios