JDK-8188897 : java/rmi/registry/reexport/Reexport.java failed with Port already in use
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.rmi
  • Affected Version: 10,11
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2017-10-09
  • Updated: 2023-09-14
  • Resolved: 2018-04-11
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 11 JDK 8
11 b09Fixed 8u401Fixed
Related Reports
Relates :  
Description
----------System.out:(2/90)----------
RegistryRunner.port.start:65162:RegistryRunner.port.end
Starting registry on port 65162
----------System.err:(157/11543)*----------

regression test for 4120329

JAVAVM: command = [C:\\ade\\mesos\\work_dir\\jib-master\\install\\jdk10-master.88\\windows-x64.jdk\\jdk-10\\bin\\java, -ea, -esa, -Xmx512m, -Djava.security.policy=C:\\ade\\mesos\\work_dir\\jib-master\\install\\jdk10-master.88\\src.full\\open\\test\\jdk\\java\\rmi\\registry\\reexport\\registry.security.policy, --add-exports=java.rmi/sun.rmi.registry=ALL-UNNAMED, --add-exports=java.rmi/sun.rmi.server=ALL-UNNAMED, --add-exports=java.rmi/sun.rmi.transport=ALL-UNNAMED, --add-exports=java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED, RegistryRunner, 0]
registry is running at port: 65162
Creating duplicate registry, this should fail...
EXPECTING PORT IN USE EXCEPTION:
Port already in use: 65162; nested exception is: 
	java.net.BindException: Address already in use: NET_Bind
java.rmi.server.ExportException: Port already in use: 65162; nested exception is: 
	java.net.BindException: Address already in use: NET_Bind
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:335)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:243)
	at java.rmi/sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:411)
	at java.rmi/sun.rmi.transport.LiveRef.exportObject(LiveRef.java:147)
	at java.rmi/sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:234)
	at java.rmi/sun.rmi.registry.RegistryImpl.setup(RegistryImpl.java:220)
	at java.rmi/sun.rmi.registry.RegistryImpl.(RegistryImpl.java:205)
	at java.rmi/java.rmi.registry.LocateRegistry.createRegistry(LocateRegistry.java:203)
	at Reexport.createReg(Reexport.java:99)
	at Reexport.main(Reexport.java:65)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:115)
	at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.net.BindException: Address already in use: NET_Bind
	at java.base/java.net.DualStackPlainSocketImpl.bind0(Native Method)
	at java.base/java.net.DualStackPlainSocketImpl.socketBind(DualStackPlainSocketImpl.java:106)
	at java.base/java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:437)
	at java.base/java.net.PlainSocketImpl.bind(PlainSocketImpl.java:174)
	at java.base/java.net.ServerSocket.bind(ServerSocket.java:381)
	at java.base/java.net.ServerSocket.(ServerSocket.java:243)
	at java.base/java.net.ServerSocket.(ServerSocket.java:135)
	at java.rmi/sun.rmi.transport.tcp.TCPDirectSocketFactory.createServerSocket(TCPDirectSocketFactory.java:45)
	at java.rmi/sun.rmi.transport.tcp.TCPEndpoint.newServerSocket(TCPEndpoint.java:666)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:324)
	... 15 more
Bringing down the first registry
Comments
URL: http://hg.openjdk.java.net/jdk/jdk/rev/25515c7e96b0 User: mli Date: 2018-04-11 01:10:19 +0000
11-04-2018

there is a time window between shutdown of first registry and startup of second registry on the same port, interlooper(another test or other program on the host) has the opportunity to occupy the port. this can not be avoided in current test env/infra, the only way to fix it is to try several times before fails. ======================== another possible reason is that first registry is not shutdown by killRegistry() before startup of second registry, but seems it's not possible, because there is a message in log: "received call to exit", after the message, it should be shutdown immediately. But on my local linux VM, I can reproduce the issue every time, it's fixed by adding Thread.sleep(100) just before the second createReg(boolean). So, I think we need to fix the issue in both ways to improve the stability. NOTE: all reported issues happened on Windows Server 2012 R2 6.3 (amd64), at the same time I can reproduce the issue on my local linux VM.
02-04-2018

Please take a look, this test has been failing a lot lately.
27-03-2018