Name: boT120536 Date: 12/21/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
This is pretty much a duplicate of Bug #4060907 found way back in Java 1.1.3.
It was marked fixed in Java 1.2beta4, but it's rearing its ugly head again in
1.3.0. I'm not sure, but I believe it also occurs in 1.2.2. It does not appear
to occur on Linux; don't know about Solaris.
The problem: Open a ServerSocket on a port. You can then close it and reopen
it on the same port ONLY if any Sockets that were established through that
ServerSocket are also closed. Otherwise you get java.net.BindExceptions stating
that the port is in use even though the ServerSocket itself was closed.
>1.Exact steps to reproduce the problem.
Run the test program below with the 's.close()' line uncommented and try and
telnet to port 1111 on localhost. It works properly, but your connections are
always immediately lost.
Then comment out the line and try running and telnetting. You get a
BindException when trying to reopen the ServerSocket.
>2.Java SOURCE CODE that demonstrates the problem, if possible.
import java.io.*;
import java.net.*;
public class BindTest {
public static void main(String[] args) {
while (true) {
ServerSocket ss = null;
try {
System.out.println("Creating socket on port
1111");
ss = new ServerSocket(1111, 10);
System.out.println("Setting timeout to 60
seconds");
ss.setSoTimeout(60000);
System.out.println("Accepting");
Socket s = ss.accept();
//s.close();
} catch (IOException e) {
System.out.println("Exception accepting: " +
e);
System.out.println(" Message: " +
e.getMessage());
e.printStackTrace();
}
System.out.println("Closing socket");
try {
ss.close();
ss = null;
System.gc();
} catch (IOException e) {
System.out.println("Exception closing: " + e);
System.out.println(" Message: " +
e.getMessage());
e.printStackTrace();
}
}
}
}
>3.Exact text of any error message(s) that appeared.
Exception accepting: java.net.BindException: Address in use: JVM_Bind
Message: Address in use: JVM_Bind
java.net.BindException: Address in use: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:397)
at java.net.ServerSocket.<init>(ServerSocket.java:170)
at java.net.ServerSocket.<init>(ServerSocket.java:121)
at BindTest.main(BindTest.java:10)
>4.Any trace information.
None.
>5.Include additional configuration information that you think is relevant to
the problem
None.
(Review ID: 109934)
======================================================================
- duplicates
-
JDK-4400234 On Win32, can't open ServerSocket on same port right after closing it
-
- Closed
-