Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
0.7.0-M2
-
None
Description
While build Brooklyn I have encountered an exception in one of the tests.
java.rmi.server.ExportException: Port already in use: 40127; nested exception is:
java.net.BindException: Address already in use
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:376)
at java.net.ServerSocket.bind(ServerSocket.java:376)
at java.net.ServerSocket.<init>(ServerSocket.java:237)
at java.net.ServerSocket.<init>(ServerSocket.java:128)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createServerSocket(RMIDirectSocketFactory.java:45)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createServerSocket(RMIMasterSocketFactory.java:349)
at sun.rmi.transport.tcp.TCPEndpoint.newServerSocket(TCPEndpoint.java:667)
at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:317)
at sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:236)
at sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:411)
at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:147)
at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:207)
at sun.rmi.registry.RegistryImpl.setup(RegistryImpl.java:122)
at sun.rmi.registry.RegistryImpl.<init>(RegistryImpl.java:108)
at java.rmi.registry.LocateRegistry.createRegistry(LocateRegistry.java:203)
at mx4j.tools.naming.NamingService.start(NamingService.java:67)
at sun.reflect.GeneratedMethodAccessor55.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:111)
at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:45)
at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:235)
at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:138)
at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:252)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:792)
at javax.management.MBeanServerInvocationHandler.invoke(MBeanServerInvocationHandler.java:305)
at com.sun.proxy.$Proxy41.start(Unknown Source)
at brooklyn.test.JmxService.<init>(JmxService.java:106)
at brooklyn.test.JmxService.<init>(JmxService.java:80)
at brooklyn.event.feed.jmx.JmxFeedTest.setUp(JmxFeedTest.java:140)
The port 40127 is being returned by LocalhostMachineProvisioningLocation.obtainPort(..) which calls through several layers to Networking.isPortAvailable(..). This checks if the port is free but appears not to release the port. This appears to be related to socket.setReuseAddress(..) being called after binding the socket. The documentation requires it to be called before.
Also an off by one error in Networking.nextAvailablePort(). The last value it passes to Networking.isPortAvailable(..) is MAX_PORT_NUMBER + 1.