Date: Mon, 11 Dec 2006 17:24:46 +0200 From: Achilleas Mantzios <achill@matrix.gatewaynet.com> To: freebsd-java@freebsd.org Subject: Re: close() of active socket does not work on FreeBSD 6 Message-ID: <200612111724.46716.achill@matrix.gatewaynet.com> In-Reply-To: <Pine.LNX.4.62.0612111535280.32258@decibel.pvv.ntnu.no> References: <Pine.LNX.4.62.0612111535280.32258@decibel.pvv.ntnu.no>
next in thread | previous in thread | raw e-mail | index | archive | help
=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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200612111724.46716.achill>