JDK-6521014 : IOException thrown when Socket tries to bind to an local IPv6 address on SuSE Linux
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6,6u11
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux,solaris_9
  • CPU: generic,sparc
  • Submitted: 2007-02-03
  • Updated: 2012-07-16
  • Resolved: 2011-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u33Fixed 7 b13Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
It seems that the Socket constructor 

public Socket(InetAddress address,
              int port,
              InetAddress localAddr,
              int localPort)

cannot successfully complete on SuSE Linux. See attached for the test program.

The program does the following:

1) Start a test server and use Socket constructor Socket(InetAddress, int) to create a connection and send some data. Both server and client are closed.

2) Start another test server and use Socket constructor Socket(InetAddress, int, InetAddress, int) to create a connection and send some data.

It is observed that when an IPv6 address is used in step 2), the Socket creation fails with the following stack trace:

/java/re/j2se/6.0/archive/fcs/binaries/linux-i586/bin/java -classpath ~/tests IPv6SocketTest fe80:0:0:0:207:e9ff:fe62:7e18
java.net.BindException: Cannot assign requested address
	at java.net.PlainSocketImpl.socketBind(Native Method)
	at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
	at java.net.Socket.bind(Socket.java:565)
	at java.net.Socket.<init>(Socket.java:364)
	at java.net.Socket.<init>(Socket.java:266)
	at IPv6SocketTest.test2(IPv6SocketTest.java:105)
	at IPv6SocketTest.main(IPv6SocketTest.java:149)
Exception during creating Socket object java.net.BindException: Cannot assign requested address

It is also found that if we skip step 1) (by commenting out test1() in main()), the Socket still cannot be created in step 2), but due to timeout instead.

Here is the network configuration:

eth0      Link encap:Ethernet  HWaddr 00:07:E9:62:7E:18  
          inet addr:129.145.163.163  Bcast:129.145.163.255  Mask:255.255.254.0
          inet6 addr: fe80::207:e9ff:fe62:7e18/64 Scope:Link
          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5919400 errors:27 dropped:0 overruns:0 frame:27
          TX packets:1425053 errors:1 dropped:0 overruns:0 carrier:1
          collisions:348412 txqueuelen:1000 
          RX bytes:1694148885 (1615.6 Mb)  TX bytes:242995518 (231.7 Mb)
          Base address:0xcc00 Memory:ff8e0000-ff900000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:93462 errors:0 dropped:0 overruns:0 frame:0
          TX packets:93462 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:17620957 (16.8 Mb)  TX bytes:17620957 (16.8 Mb)

Here is the host information:

Linux d-usca22-163-163 2.6.4-52-smp #1 SMP Wed Apr 7 02:11:20 UTC 2004 i686 i686 i386 GNU/Linux

It is observed that the problem does not exist if an IPv4 address is used as an argument to the program, or if the program is executed on Solaris.

Comments
EVALUATION The problem is twofold: - The scope_id cache used in NET_InetAddressToSockaddr() may cause a wrong scope_id being calcaulated. - Even if the scope_id cahce get disabled, the attached test still fails with a 'time out' exception instead of a bind error. It is found that if one Linux box sends to its own link-local address some data, it can't get those data due to Linux IPv6 stack problem. 6529807 will track that half of the problem. This CR will only resolve scope_id issue.
2007-03-01