Name: md23716 Date: 10/05/2001
On Solaris 8, a Java process can bind to the same port number as a running IPv6 service. There are no socket exceptions - any IPv4 connections get directed to the Java process, rather than the IPv6 service.
On Solaris 7, the same Java program receives a BindException - "Address already in use". ( This is because Solaris 7 services use IPv4, there is no support for IPv6. )
The problem is occurring on 1.3.1_01 HotSpot JDK, but is fixed in 1.4 under bug 4417734.
To recreate the problem, compile the following testcase and run (as root):
java InUseSocket 23 1000000
Then try to telnet in from a Solaris 7 machine.
-------------------TESTCASE----------------------------------------
import java.net.*;
import java.io.*;
public class InUseSocket
{
private int port;
private int timeout;
public InUseSocket(int _port, int _timeout)
{
this.port = _port;
this.timeout = _timeout;
}
public static void main(String[] args)
{
if (args.length < 1)
{
System.out.println("Usage: InUseSocket <port number> (<timeout>)");
System.exit(1);
}
int _port = 1;
try
{
_port = Integer.parseInt(args[0]);
}
catch(Exception e)
{
System.out.println("Error invalid port number: " + e);
System.exit(1);
}
int _timeout = 1000;
if (args.length == 2)
{
try
{
_timeout = Integer.parseInt(args[1]);
}
catch(Exception e)
{
System.out.println("Error invalid timeout number: " + e);
System.exit(1);
}
}
InUseSocket sock = new InUseSocket(_port, _timeout);
sock.run();
}
private void run()
{
ServerSocket serverSock = null;
try
{
serverSock = new ServerSocket(port);
serverSock.setSoTimeout(timeout);
}
catch(Exception e)
{
System.out.println("Error creating socket: " + e);
System.exit(1);
}
try
{
serverSock.accept();
}
catch(InterruptedIOException e)
{
System.out.println("Finished properly.");
}
catch(Exception e)
{
System.out.println("Error accepting on socket: " + e);
System.exit(1);
}
}
}
======================================================================
- duplicates
-
JDK-4417734 On Solaris 8 no BindException thrown if bind to IPv4 address whilst bound to ::
- Closed