JDK-8072466 : Deadlock when initializing MulticastSocket and DatagramSocket
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7u60,8u25
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7,windows_8
  • CPU: x86
  • Submitted: 2014-12-12
  • Updated: 2016-08-24
  • Resolved: 2015-09-09
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 Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8 JDK 9
7u95Fixed 8u72Fixed 9 b82Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Same experience on multiple windows platforms
and with 1.7.51 and 1.8.25

A DESCRIPTION OF THE PROBLEM :
java deadlocks when 
MulticastSocket and DatagramSocket sockets are created at the same time in 2 threads

REGRESSION.  Last worked in version 7u51

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
// Threads 1 - Listener for DatagramPacket
new MulticastSocket(6000);

// Thread 2 - DatagramPacket Sender
new DatagramSocket(6000);


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Occasionally deadlocks with following stack trace for both threads

Thread [MulticastSender]
	waiting for: (id=21)	
	AbstractPlainDatagramSocketImpl.init() line: not available [native method]	AbstractPlainDatagramSocketImpl.<clinit>() line: not available	
	DefaultDatagramSocketImplFactory.createDatagramSocketImpl(boolean) line: not available	
	DatagramSocket.createImpl() line: not available	
	DatagramSocket.<init>(SocketAddress) line: not available	
	DatagramSocket.<init>(int, InetAddress) line: not available	
	DatagramSocket.<init>(int) line: not available	
	MulticastSender.<init>(InetAddress, int, InetAddress) line: 35	
	
MulticastSender.init line 35 is: ds = new DatagramSocket(port);



Thread [MulticastReceiver] (Suspended)	
	waiting for: (id=27)	
	DefaultDatagramSocketImplFactory.createDatagramSocketImpl(boolean) line: not available	
	MulticastSocket(DatagramSocket).createImpl() line: not available	
	MulticastSocket(DatagramSocket).<init>(SocketAddress) line: not available	
	MulticastSocket.<init>(SocketAddress) line: not available	
	MulticastSocket.<init>(int) line: not available	
	MulticastReceiver.run() line: 48	
 
where MulticastReceiver.run line 48: ms = new MulticastSocket(port);

REPRODUCIBILITY :
This bug can be reproduced occasionally.

CUSTOMER SUBMITTED WORKAROUND :
synchronize construction


Comments
The review respinned: http://mail.openjdk.java.net/pipermail/core-libs-dev/2015-September/035041.html A regression test was added.
07-09-2015

Will need to re-request the review: http://mail.openjdk.java.net/pipermail/core-libs-dev/2015-February/031560.html
21-04-2015

And yes, with the reproduce above a deadlock was observed too. All the threads are blocked with these stacktraces: "Thread-2047" prio=6 tid=0x000000006300e000 nid=0x338c in Object.wait() [0x00000000ba3ce000] java.lang.Thread.State: RUNNABLE JavaThread state: _thread_blocked Thread: 0x000000006300e000 [0x338c] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0 JavaThread state: _thread_blocked at java.net.DefaultDatagramSocketImplFactory.createDatagramSocketImpl(DefaultDatagramSocketImplFactory.java:132) at java.net.DatagramSocket.createImpl(DatagramSocket.java:336) at java.net.DatagramSocket.<init>(DatagramSocket.java:249) at java.net.DatagramSocket.<init>(DatagramSocket.java:304) at java.net.DatagramSocket.<init>(DatagramSocket.java:276) at MultiDead$2.run(MultiDead.java:25) at java.lang.Thread.run(Thread.java:745) "Thread-2046" prio=6 tid=0x000000006300d000 nid=0x3388 in Object.wait() [0x00000000ba23f000] java.lang.Thread.State: RUNNABLE JavaThread state: _thread_blocked Thread: 0x000000006300d000 [0x3388] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0 JavaThread state: _thread_blocked at java.net.DefaultDatagramSocketImplFactory.createDatagramSocketImpl(DefaultDatagramSocketImplFactory.java:134) at java.net.DatagramSocket.createImpl(DatagramSocket.java:336) at java.net.DatagramSocket.<init>(DatagramSocket.java:249) at java.net.MulticastSocket.<init>(MulticastSocket.java:166) at java.net.MulticastSocket.<init>(MulticastSocket.java:137) at MultiDead$1.run(MultiDead.java:15) at java.lang.Thread.run(Thread.java:745) I wonder, if AbstractPlainDatagramSocketImpl.c: ... two_stacks_clazz = (*env)->FindClass(env, "java/net/TwoStacksPlainDatagramSocketImpl"); ... can be related to this.
09-02-2015

probably fix of JDK-8001227 may help.
06-02-2015

I think it is informative to execute the creation of the DatagramSocket and the MulticastSocket as a serial execution this will provide a baseline for what the concurrent execution of the two Socket instantiation should be. DatagramSocket first MulticastSocket second $ java -cp . MulticastSocketDatagramSocketSerialCreationTest main: create DatagramSocket main: DatagramSocket created main: create MulticastSocket java.net.SocketException: Unrecognized Windows Sockets error: 0: Cannot bind at java.net.TwoStacksPlainDatagramSocketImpl.bind0(Native Method) at java.net.TwoStacksPlainDatagramSocketImpl.bind0(Unknown Source) at java.net.AbstractPlainDatagramSocketImpl.bind(Unknown Source) at java.net.TwoStacksPlainDatagramSocketImpl.bind(Unknown Source) at java.net.DatagramSocket.bind(Unknown Source) at java.net.MulticastSocket.<init>(Unknown Source) at java.net.MulticastSocket.<init>(Unknown Source) at MulticastSocketDatagramSocketSerialCreationTest.main(MulticastSocketDatagramSocketSerialCreationTest.java:19) Exception: java.net.SocketException: Unrecognized Windows Sockets error: 0: Cannot bind and alternatively MulticastSocket first DatagramSocket second $ java -cp . MulticastSocketDatagramSocketSerialCreationTest main: create MulticastSocket main: MulticastSocket created main: create DatagramSocket main: DatagramSocket created then MulticastSocket DatagramSocket MulticastSocket $ java -cp . MulticastSocketDatagramSocketSerialCreationTest main: create MulticastSocket main: MulticastSocket created main: create DatagramSocket main: DatagramSocket created main: create MulticastSocket main: MulticastSocket created then DatagramSocket MulticastSocket MulticastSocket java -cp . MulticastSocketDatagramSocketSerialCreationTest main: create DatagramSocket main: DatagramSocket created main: create MulticastSocket java.net.SocketException: Unrecognized Windows Sockets error: 0: Cannot bind at java.net.TwoStacksPlainDatagramSocketImpl.bind0(Native Method) at java.net.TwoStacksPlainDatagramSocketImpl.bind0(Unknown Source) at java.net.AbstractPlainDatagramSocketImpl.bind(Unknown Source) at java.net.TwoStacksPlainDatagramSocketImpl.bind(Unknown Source) at java.net.DatagramSocket.bind(Unknown Source) at java.net.MulticastSocket.<init>(Unknown Source) at java.net.MulticastSocket.<init>(Unknown Source) at MulticastSocketDatagramSocketSerialCreationTest.createMulticastSocket(MulticastSocketDatagramSocketSerialCreationTest.java:36) at MulticastSocketDatagramSocketSerialCreationTest.main(MulticastSocketDatagramSocketSerialCreationTest.java:20) main: create MulticastSocket java.net.SocketException: Unrecognized Windows Sockets error: 0: Cannot bind at java.net.TwoStacksPlainDatagramSocketImpl.bind0(Native Method) at java.net.TwoStacksPlainDatagramSocketImpl.bind0(Unknown Source) at java.net.AbstractPlainDatagramSocketImpl.bind(Unknown Source) at java.net.TwoStacksPlainDatagramSocketImpl.bind(Unknown Source) at java.net.DatagramSocket.bind(Unknown Source) at java.net.MulticastSocket.<init>(Unknown Source) at java.net.MulticastSocket.<init>(Unknown Source) at MulticastSocketDatagramSocketSerialCreationTest.createMulticastSocket(MulticastSocketDatagramSocketSerialCreationTest.java:36) at MulticastSocketDatagramSocketSerialCreationTest.main(MulticastSocketDatagramSocketSerialCreationTest.java:24) Exception: java.net.SocketException: Unrecognized Windows Sockets error: 0: Cannot bind There should be consistency across all scenarios once the DatagramSocket has been created first then a MulticastSocket can not be properly created together with the lower level concurrency issue identified, there would appear to be a flaw in the DefaultDatagramSocketImplFactory, as the concurrent execution will permit (sometimes) that which a serial execution prohibits. synchronizing the DefaultDatagramSocketImplFactory.createDatagramSocketImpl() method will give more consistent behaviour across all scenarios and eliminate the deadlock.
06-02-2015

Java stack only attached in jstack.log
06-02-2015

Reproducer not provided to proceed with.
30-01-2015

Sent an email to submitter requesting a simple test case.
17-12-2014