Skip to content

Commit

Permalink
Added tracking for the negotiate request so calling stop properly abo…
Browse files Browse the repository at this point in the history
…rts the request.

- Without aborting the negotiate request starting and stopping in quick succession can cause multiple active ajax requests attempting to connect.

#2160
  • Loading branch information
NTaylorMullen committed Jun 21, 2013
1 parent 4a60670 commit f95f940
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 29 deletions.
Expand Up @@ -249,7 +249,8 @@
connectingMessageBuffer: new ConnectingMessageBuffer(this, function (message) {
$connection.triggerHandler(events.onReceived, [message]);
}),
onFailedTimeoutHandle: null
onFailedTimeoutHandle: null,
negotiateAbortText: "__Negotiate Aborted__"
};
if (typeof (logging) === "boolean") {
this.logging = logging;
Expand Down Expand Up @@ -527,19 +528,24 @@
});

connection.log("Negotiating with '" + url + "'.");
$.ajax({

// Save the ajax negotiate request object so we can abort it if stop is called while the request is in flight.
connection._.negotiateRequest = $.ajax({
url: url,
global: false,
cache: false,
type: "GET",
contentType: connection.contentType,
data: {},
dataType: connection.ajaxDataType,
error: function (error) {
$(connection).triggerHandler(events.onError, [error.responseText]);
deferred.reject("SignalR: Error during negotiation request: " + error.responseText);
// Stop the connection if negotiate failed
connection.stop();
error: function (error, statusText) {
// We don't want to cause any errors if we're aborting our own negotiate request.
if (statusText !== connection._.negotiateAbortText) {
$(connection).triggerHandler(events.onError, [error.responseText]);
deferred.reject("SignalR: Error during negotiation request: " + error.responseText);
// Stop the connection if negotiate failed
connection.stop();
}
},
success: function (result) {
var res = connection._parseResponse(result),
Expand Down Expand Up @@ -768,6 +774,12 @@
connection.transport = null;
}

if (connection._.negotiateRequest) {
// If the negotiation request has already completed this will noop.
connection._.negotiateRequest.abort(connection._.negotiateAbortText);
delete connection._.negotiateRequest;
}

// Trigger the disconnect event
$(connection).triggerHandler(events.onDisconnect);

Expand Down
26 changes: 19 additions & 7 deletions samples/Microsoft.AspNet.SignalR.Samples/Scripts/jquery.signalR.js
Expand Up @@ -249,7 +249,8 @@
connectingMessageBuffer: new ConnectingMessageBuffer(this, function (message) {
$connection.triggerHandler(events.onReceived, [message]);
}),
onFailedTimeoutHandle: null
onFailedTimeoutHandle: null,
negotiateAbortText: "__Negotiate Aborted__"
};
if (typeof (logging) === "boolean") {
this.logging = logging;
Expand Down Expand Up @@ -527,19 +528,24 @@
});

connection.log("Negotiating with '" + url + "'.");
$.ajax({

// Save the ajax negotiate request object so we can abort it if stop is called while the request is in flight.
connection._.negotiateRequest = $.ajax({
url: url,
global: false,
cache: false,
type: "GET",
contentType: connection.contentType,
data: {},
dataType: connection.ajaxDataType,
error: function (error) {
$(connection).triggerHandler(events.onError, [error.responseText]);
deferred.reject("SignalR: Error during negotiation request: " + error.responseText);
// Stop the connection if negotiate failed
connection.stop();
error: function (error, statusText) {
// We don't want to cause any errors if we're aborting our own negotiate request.
if (statusText !== connection._.negotiateAbortText) {
$(connection).triggerHandler(events.onError, [error.responseText]);
deferred.reject("SignalR: Error during negotiation request: " + error.responseText);
// Stop the connection if negotiate failed
connection.stop();
}
},
success: function (result) {
var res = connection._parseResponse(result),
Expand Down Expand Up @@ -768,6 +774,12 @@
connection.transport = null;
}

if (connection._.negotiateRequest) {
// If the negotiation request has already completed this will noop.
connection._.negotiateRequest.abort(connection._.negotiateAbortText);
delete connection._.negotiateRequest;
}

// Trigger the disconnect event
$(connection).triggerHandler(events.onDisconnect);

Expand Down

Large diffs are not rendered by default.

26 changes: 19 additions & 7 deletions src/Microsoft.AspNet.SignalR.Client.JS/jquery.signalR.core.js
Expand Up @@ -248,7 +248,8 @@
connectingMessageBuffer: new ConnectingMessageBuffer(this, function (message) {
$connection.triggerHandler(events.onReceived, [message]);
}),
onFailedTimeoutHandle: null
onFailedTimeoutHandle: null,
negotiateAbortText: "__Negotiate Aborted__"
};
if (typeof (logging) === "boolean") {
this.logging = logging;
Expand Down Expand Up @@ -526,19 +527,24 @@
});

connection.log("Negotiating with '" + url + "'.");
$.ajax({

// Save the ajax negotiate request object so we can abort it if stop is called while the request is in flight.
connection._.negotiateRequest = $.ajax({
url: url,
global: false,
cache: false,
type: "GET",
contentType: connection.contentType,
data: {},
dataType: connection.ajaxDataType,
error: function (error) {
$(connection).triggerHandler(events.onError, [error.responseText]);
deferred.reject("SignalR: Error during negotiation request: " + error.responseText);
// Stop the connection if negotiate failed
connection.stop();
error: function (error, statusText) {
// We don't want to cause any errors if we're aborting our own negotiate request.
if (statusText !== connection._.negotiateAbortText) {
$(connection).triggerHandler(events.onError, [error.responseText]);
deferred.reject("SignalR: Error during negotiation request: " + error.responseText);
// Stop the connection if negotiate failed
connection.stop();
}
},
success: function (result) {
var res = connection._parseResponse(result),
Expand Down Expand Up @@ -767,6 +773,12 @@
connection.transport = null;
}

if (connection._.negotiateRequest) {
// If the negotiation request has already completed this will noop.
connection._.negotiateRequest.abort(connection._.negotiateAbortText);
delete connection._.negotiateRequest;
}

// Trigger the disconnect event
$(connection).triggerHandler(events.onDisconnect);

Expand Down
Expand Up @@ -249,7 +249,8 @@
connectingMessageBuffer: new ConnectingMessageBuffer(this, function (message) {
$connection.triggerHandler(events.onReceived, [message]);
}),
onFailedTimeoutHandle: null
onFailedTimeoutHandle: null,
negotiateAbortText: "__Negotiate Aborted__"
};
if (typeof (logging) === "boolean") {
this.logging = logging;
Expand Down Expand Up @@ -527,19 +528,24 @@
});

connection.log("Negotiating with '" + url + "'.");
$.ajax({

// Save the ajax negotiate request object so we can abort it if stop is called while the request is in flight.
connection._.negotiateRequest = $.ajax({
url: url,
global: false,
cache: false,
type: "GET",
contentType: connection.contentType,
data: {},
dataType: connection.ajaxDataType,
error: function (error) {
$(connection).triggerHandler(events.onError, [error.responseText]);
deferred.reject("SignalR: Error during negotiation request: " + error.responseText);
// Stop the connection if negotiate failed
connection.stop();
error: function (error, statusText) {
// We don't want to cause any errors if we're aborting our own negotiate request.
if (statusText !== connection._.negotiateAbortText) {
$(connection).triggerHandler(events.onError, [error.responseText]);
deferred.reject("SignalR: Error during negotiation request: " + error.responseText);
// Stop the connection if negotiate failed
connection.stop();
}
},
success: function (result) {
var res = connection._parseResponse(result),
Expand Down Expand Up @@ -768,6 +774,12 @@
connection.transport = null;
}

if (connection._.negotiateRequest) {
// If the negotiation request has already completed this will noop.
connection._.negotiateRequest.abort(connection._.negotiateAbortText);
delete connection._.negotiateRequest;
}

// Trigger the disconnect event
$(connection).triggerHandler(events.onDisconnect);

Expand Down

0 comments on commit f95f940

Please sign in to comment.