close() of active socket does not work on FreeBSD 6
Achilleas Mantzios
achill at matrix.gatewaynet.com
Mon Dec 11 07:25:23 PST 2006
Στις Δευτέρα 11 Δεκέμβριος 2006 16:46, ο/η Arne H. Juul έγραψε:
> 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
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 = null;
>
> public FooConn(int port) {
> super("FooConn:" + port);
> this.port = port;
> this.alive = true;
> }
> private void connect() {
> while (socket == null) {
> try {
> socket = new Socket("localhost", port);
> } catch(IOException e) {
> System.err.println("Connect failed: " + e);
> try { Thread.sleep(1000); } catch(InterruptedException ie)
> {}
> }
> }
> }
> public void disconnect() throws IOException, InterruptedException {
> alive = false;
> System.out.println("closing socket");
> socket.close();
> System.out.println("calling join");
> join();
> }
> public void run() {
> while (alive) {
> if (socket == null) {
> System.out.println("socket null, connect");
> connect();
> }
> try {
> int b = socket.getInputStream().read();
> System.out.println("got byte "+ b);
> } catch (IOException e) {
> System.out.println("IOException, set socket to null");
> socket = null; //triggers reconnect
> } catch (RuntimeException e) {
> System.err.println("RuntimeException "+e);
> return;
> }
> }
> }
> public static void main(String[] args) throws IOException {
> try {
> FooConn conn = new FooConn(22);
> conn.start();
> Thread.sleep(1000);
> conn.disconnect();
> } catch(InterruptedException ie) {}
> }
> }
> _______________________________________________
> freebsd-java at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-java
> To unsubscribe, send any mail to "freebsd-java-unsubscribe at freebsd.org"
--
Achilleas Mantzios
More information about the freebsd-java
mailing list