Bug 921850 - Fix races in debugger client when connecting agressively r=past

This commit is contained in:
Alexandre Poirot 2013-10-21 01:56:00 +03:00
parent baccb13238
commit c85eee31d0
3 changed files with 38 additions and 5 deletions

View File

@ -54,7 +54,14 @@ function submit() {
Services.prefs.setIntPref("devtools.debugger.remote-port", port);
// Initiate the connection
let transport = debuggerSocketConnect(host, port);
let transport;
try {
transport = debuggerSocketConnect(host, port);
} catch(e) {
// Bug 921850: catch rare exception from debuggerSocketConnect
showError("unexpected");
return;
}
gClient = new DebuggerClient(transport);
let delay = Services.prefs.getIntPref("devtools.debugger.remote-timeout");
gConnectionTimeout = setTimeout(handleConnectionTimeout, delay);

View File

@ -221,7 +221,17 @@ Connection.prototype = {
if (!this.host) {
transport = DebuggerServer.connectPipe();
} else {
transport = debuggerSocketConnect(this.host, this.port);
try {
transport = debuggerSocketConnect(this.host, this.port);
} catch (e) {
// In some cases, especially on Mac, the openOutputStream call in
// debuggerSocketConnect may throw NS_ERROR_NOT_INITIALIZED.
// It occurs when we connect agressively to the simulator,
// and keep trying to open a socket to the server being started in
// the simulator.
this._onDisconnected();
return;
}
}
this._client = new DebuggerClient(transport);
this._client.addOneTimeListener("closed", this._onDisconnected);
@ -244,7 +254,7 @@ Connection.prototype = {
this._client = null;
if (this._status == Connection.Status.CONNECTING && this.keepConnecting) {
setTimeout(() => this._clientConnect(), 0);
setTimeout(() => this._clientConnect(), 100);
return;
}

View File

@ -2200,8 +2200,24 @@ eventSource(EnvironmentClient.prototype);
this.debuggerSocketConnect = function debuggerSocketConnect(aHost, aPort)
{
let s = socketTransportService.createTransport(null, 0, aHost, aPort, null);
let transport = new DebuggerTransport(s.openInputStream(0, 0, 0),
s.openOutputStream(0, 0, 0));
// By default the CONNECT socket timeout is very long, 65535 seconds,
// so that if we race to be in CONNECT state while the server socket is still
// initializing, the connection is stuck in connecting state for 18.20 hours!
s.setTimeout(Ci.nsISocketTransport.TIMEOUT_CONNECT, 2);
// openOutputStream may throw NS_ERROR_NOT_INITIALIZED if we hit some race
// where the nsISocketTransport gets shutdown in between its instantiation and
// the call to this method.
let transport;
try {
transport = new DebuggerTransport(s.openInputStream(0, 0, 0),
s.openOutputStream(0, 0, 0));
} catch(e) {
let msg = e + ": " + e.stack;
Cu.reportError(msg);
dumpn(msg);
throw e;
}
return transport;
}