Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 322266 - [JUnit] JUnit launch target fails to start because port is released and reacquired
Summary: [JUnit] JUnit launch target fails to start because port is released and reacq...
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-10 14:22 EDT by Michael Schneider CLA
Modified: 2019-10-18 12:05 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Schneider CLA 2010-08-10 14:22:51 EDT
Build Identifier: I20100603-1500

It looks as if my launch target accidentally acquires the same port as Eclipse shortly after launching. Later on, the RemoteTestRunner cannot connect back to Eclipse.

See stack trace:

Reproducible: Sometimes

Steps to Reproduce:
Could not connect to:  : 54916			
java.net.ConnectException: Connection refused: connect
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
	at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:367)
	at java.net.Socket.connect(Socket.java:524)
	at java.net.Socket.connect(Socket.java:474)
	at java.net.Socket.<init>(Socket.java:371)
	at java.net.Socket.<init>(Socket.java:184)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.connect(RemoteTestRunner.java:570)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:381)
	at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
	at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.run(CoreTestApplication.java:23)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:592)
	at org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:574)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:592)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
Comment 1 Markus Keller CLA 2010-08-11 06:51:10 EDT
org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate#evaluatePort() finds a free port and stores it as a launch attribute.

Later, JUnitLaunchListener#launchChanged(ILaunch) reads the port and in the end, RemoteTestRunnerClient.ServerConnection#run() opens the ServerSocket again.

In between, there's an opportunity for others to take the same port. We should open the socket only once and pass it on to the ServerConnection.
Comment 2 Markus Keller CLA 2011-04-25 15:09:35 EDT
The fix is not as trivial as it sounds. We cannot directly pass the ServerSocket, since Debug implements the launching and we don't have a channel to pass arbitrary objects from JUnitLaunchConfigurationDelegate to the RemoteTestRunnerClient.ServerConnection (or to the ILaunch).

We need to go via a static cache in JUnitModel, and we have to make sure that ServerSockets are closed eventually, even if launching failed (so a WeakHashMap is not enough).

Furthermore, when I tested SocketUtil.findFreePort() on Windows 7, I got an increased value on each call, even if the port was not used in between. So clashing ports shouldn't be an issue with well-behaved other parties that also use "new ServerSocket(0)" instead of a home-brewed port number finder.
Comment 3 Eclipse Genie CLA 2019-10-18 12:05:12 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.