Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 351724 - JDT Debug Jvm_bind exception when clicking debug second time
Summary: JDT Debug Jvm_bind exception when clicking debug second time
Status: RESOLVED NOT_ECLIPSE
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-11 11:01 EDT by Andy CLA
Modified: 2012-04-12 13:40 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andy CLA 2011-07-11 11:01:28 EDT
Build Identifier: 3.6

java.version=1.6.0_13
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_CA
Command-line arguments:  -os win32 -ws win32 -arch x86_64


Error
Mon Jul 11 10:58:57 EDT 2011
Cannot connect to VM

java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind
	at java.net.PlainSocketImpl.socketBind(Native Method)
	at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
	at java.net.ServerSocket.bind(ServerSocket.java:319)
	at java.net.ServerSocket.<init>(ServerSocket.java:185)
	at java.net.ServerSocket.<init>(ServerSocket.java:97)
	at org.eclipse.jdi.internal.connect.SocketTransportService.startListening(SocketTransportService.java:277)
	at org.eclipse.jdi.internal.connect.SocketTransportImpl.startListening(SocketTransportImpl.java:47)
	at org.eclipse.jdi.internal.connect.SocketListeningConnectorImpl.startListening(SocketListeningConnectorImpl.java:115)
	at org.eclipse.jdt.internal.launching.StandardVMDebugger.run(StandardVMDebugger.java:246)
	at org.testng.eclipse.launch.TestNGLaunchConfigurationDelegate.launch(TestNGLaunchConfigurationDelegate.java:80)
	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:853)
	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:702)
	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:923)
	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1126)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)



Reproducible: Always

Steps to Reproduce:
1. Create a simple java main class
2.  Attempt to debug the main class
3. Works once.
4. Attempt to debug again fails.
Comment 1 Andy CLA 2011-07-11 11:08:55 EDT
Get this pop up as well: 

Cannot connect to VM
Unrecognized Windows Sockets error: 0: JVM_Bind
Comment 2 Michael Rennie CLA 2011-07-11 14:20:03 EDT
(In reply to comment #1)
> Get this pop up as well: 
> 
> Cannot connect to VM
> Unrecognized Windows Sockets error: 0: JVM_Bind

I'm not sure what the TestNGLaunchConfigurationDelegate is, but it is not provided by JDT debug. From the looks of your trace though you are trying to start listening on the same port more than once, hence the bind exception.
Comment 3 Samrat Dhillon CLA 2012-02-08 19:05:58 EST
I encounter this bug while running VPN software (netmotion) and debugging with eclipse 3.7 on Jdk 1.6.0_29. If I run eclipse using JDK 1.7 this bug is not encountered. Perhaps this was a bug in Jdk 1.6 itself. I do see that when eclipse starts the debugger it tries to find a free port using org.eclipse.jdt.launching.SocketUtil findFreePort method.  The method looks like

public static int findFreePort() {
		ServerSocket socket= null;
		try {
		socket= new ServerSocket(0);
	return socket.getLocalPort();
					} catch (IOException e) { 
		} finally {
			if (socket != null) {
				try {
					socket.close();
				} catch (IOException e) {
				}
			}
		}
		return -1;		
	}	

Should it be something like?

public static int findFreePort() {
		ServerSocket socket= null;
		try {
		socket= new ServerSocket(0);
socket.setReuseAddress(true);
	return socket.getLocalPort();
					} catch (IOException e) { 
		} finally {
			if (socket != null) {
				try {
					socket.close();
				} catch (IOException e) {
				}
			}
		}
		return -1;		
	}
Comment 4 Jacky Z CLA 2012-04-12 13:40:22 EDT
If adding Thead.sleep(5) after findFreePort() call, it will work. Not sure this is a JDK issue or OS issue.

I have colleagues have same issue. we are on 64 machine, jdk and eclipse both 64.