IDEA-156429 Debugger regularly shows "Address already in use"

This commit is contained in:
Egor.Ushakov
2016-05-25 21:10:45 +03:00
parent 28dd64910a
commit 1345724929
3 changed files with 27 additions and 8 deletions
@@ -15,12 +15,11 @@
*/
package com.intellij.debugger;
import com.intellij.debugger.impl.DebuggerManagerImpl;
import com.intellij.debugger.settings.DebuggerSettings;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.ExecutionResult;
import com.intellij.execution.configurations.RemoteConnection;
import com.intellij.execution.configurations.RemoteState;
import com.intellij.execution.configurations.RunProfileState;
import com.intellij.execution.configurations.SearchScopeProvider;
import com.intellij.execution.configurations.*;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NotNull;
@@ -31,6 +30,7 @@ public class DefaultDebugEnvironment implements DebugEnvironment {
private final boolean myPollConnection;
private final ExecutionEnvironment environment;
private final RunProfileState state;
private final boolean myNeedParametersSet;
public DefaultDebugEnvironment(@NotNull ExecutionEnvironment environment, @NotNull RunProfileState state, RemoteConnection remoteConnection, boolean pollConnection) {
this.environment = environment;
@@ -39,10 +39,19 @@ public class DefaultDebugEnvironment implements DebugEnvironment {
myPollConnection = pollConnection;
mySearchScope = SearchScopeProvider.createSearchScope(environment.getProject(), environment.getRunProfile());
myNeedParametersSet = remoteConnection.isServerMode() && remoteConnection.isUseSockets() && "0".equals(remoteConnection.getAddress());
}
@Override
public ExecutionResult createExecutionResult() throws ExecutionException {
// debug port may have changed, reinit parameters just in case
if (myNeedParametersSet && state instanceof JavaCommandLine) {
DebuggerManagerImpl.createDebugParameters(((JavaCommandLine)state).getJavaParameters(),
true,
DebuggerSettings.SOCKET_TRANSPORT,
myRemoteConnection.getAddress(),
false);
}
return state.execute(environment.getExecutor(), environment.getRunner());
}
@@ -493,7 +493,7 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb
if (address == null) {
throw new CantRunException(DebuggerBundle.message("error.no.debug.listen.port"));
}
// negative port number means the caller leaves to debugger to decide at which port to listen
// zero port number means the caller leaves to debugger to decide at which port to listen
//noinspection HardCodedStringLiteral
final Connector.Argument portArg = myConnection.isUseSockets() ? myArguments.get("port") : myArguments.get("name");
if (portArg != null) {
@@ -504,7 +504,13 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb
if (timeoutArg != null) {
timeoutArg.setValue("0"); // wait forever
}
connector.startListening(myArguments);
String listeningAddress = connector.startListening(myArguments);
String port = StringUtil.substringAfter(listeningAddress, ":");
if (port != null) {
listeningAddress = port;
}
myConnection.setAddress(listeningAddress);
myDebugProcessDispatcher.getMulticaster().connectorIsReady();
try {
return connector.accept(myArguments);
@@ -73,8 +73,12 @@ public class GenericDebuggerRunner extends JavaPatchableProgramRunner<GenericDeb
isPollConnection = ((RemoteConnectionCreator)state).isPollConnection();
}
if (connection == null) {
connection =
DebuggerManagerImpl.createDebugParameters(parameters, true, DebuggerSettings.getInstance().DEBUGGER_TRANSPORT, "", false);
int transport = DebuggerSettings.getInstance().DEBUGGER_TRANSPORT;
connection = DebuggerManagerImpl.createDebugParameters(parameters,
true,
transport,
transport == DebuggerSettings.SOCKET_TRANSPORT ? "0" : "",
false);
isPollConnection = true;
}
return attachVirtualMachine(state, environment, connection, isPollConnection);