Skip to content

Commit

Permalink
Altered how the transports handled failed parsing cases.
Browse files Browse the repository at this point in the history
- If transports fail to parse a response while in connecting they will now fall back.
- Centralized this logic in the common.js

#2506
  • Loading branch information
NTaylorMullen committed Nov 5, 2013
1 parent b5831f8 commit 2bc7887
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,18 @@
}
},

handleParseFailure: function (connection, result, errorMessage, onFailed) {
// If we're in the initialization phase trigger onFailed, otherwise stop the connection.
if (connection.state === signalR.connectionState.connecting) {
connection.log("Failed to parse server response while attempting to connect.");
onFailed();
}
else {
$(connection).triggerHandler(events.onError, ["SignalR: failed at parsing response: " + result + ". With error: " + errorMessage]);
connection.stop();
}
},

foreverFrame: {
count: 0,
connections: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@
onSuccess();
connection.log("Longpolling connected.");
},
tryFailConnect = function () {
if (onFailed) {
onFailed();
onFailed = null;
connection.log("LongPolling failed to connect.");
return true;
}

return false;
},
privateData = connection._,
reconnectErrors = 0,
fireReconnected = function (instance) {
Expand Down Expand Up @@ -123,8 +133,7 @@
minData = connection._parseResponse(result);
}
catch (error) {
$(connection).triggerHandler(events.onError, ["SignalR: failed at parsing response: " + result + ". With error: " + error.message]);
connection.stop();
transportLogic.handleParseFailure(instance, result, error.message, tryFailConnect);
return;
}

Expand Down Expand Up @@ -181,39 +190,41 @@
return;
}

// Increment our reconnect errors, we assume all errors to be reconnect errors
// In the case that it's our first error this will cause Reconnect to be fired
// after 1 second due to reconnectErrors being = 1.
reconnectErrors++;
if (!tryFailConnect()) {
// Increment our reconnect errors, we assume all errors to be reconnect errors
// In the case that it's our first error this will cause Reconnect to be fired
// after 1 second due to reconnectErrors being = 1.
reconnectErrors++;

if (connection.state !== signalR.connectionState.reconnecting) {
connection.log("An error occurred using longPolling. Status = " + textStatus + ". Response = " + data.responseText + ".");
$(instance).triggerHandler(events.onError, [data.responseText]);
}

// We check the state here to verify that we're not in an invalid state prior to verifying Reconnect.
// If we're not in connected or reconnecting then the next ensureReconnectingState check will fail and will return.
// Therefore we don't want to change that failure code path.
if ((connection.state === signalR.connectionState.connected ||
connection.state === signalR.connectionState.reconnecting) &&
!transportLogic.verifyReconnect(connection)) {
return;
}

if (connection.state !== signalR.connectionState.reconnecting) {
connection.log("An error occurred using longPolling. Status = " + textStatus + ". Response = " + data.responseText + ".");
$(instance).triggerHandler(events.onError, [data.responseText]);
}

// We check the state here to verify that we're not in an invalid state prior to verifying Reconnect.
// If we're not in connected or reconnecting then the next ensureReconnectingState check will fail and will return.
// Therefore we don't want to change that failure code path.
if ((connection.state === signalR.connectionState.connected ||
connection.state === signalR.connectionState.reconnecting) &&
!transportLogic.verifyReconnect(connection)) {
return;
}
// Transition into the reconnecting state
// If this fails then that means that the user transitioned the connection into the disconnected or connecting state within the above error handler trigger.
if (!transportLogic.ensureReconnectingState(instance)) {
return;
}

// Transition into the reconnecting state
// If this fails then that means that the user transitioned the connection into the disconnected or connecting state within the above error handler trigger.
if (!transportLogic.ensureReconnectingState(instance)) {
return;
privateData.pollTimeoutId = window.setTimeout(function () {
// If we've errored out we need to verify that the server is still there, so re-start initialization process
// This will ping the server until it successfully gets a response.
that.init(instance, function () {
// Call poll with the raiseReconnect flag as true
poll(instance, true);
});
}, that.reconnectDelay);
}

privateData.pollTimeoutId = window.setTimeout(function () {
// If we've errored out we need to verify that the server is still there, so re-start initialization process
// This will ping the server until it successfully gets a response.
that.init(instance, function () {
// Call poll with the raiseReconnect flag as true
poll(instance, true);
});
}, that.reconnectDelay);
}
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@
res = connection._parseResponse(e.data);
}
catch (error) {
$(connection).triggerHandler(events.onError, ["SignalR: failed at parsing response: " + e.data + ". With error: " + error.message]);
connection.stop();
transportLogic.handleParseFailure(connection, e.data, error.message, onFailed);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@
data = connection._parseResponse(event.data);
}
catch (error) {
$connection.triggerHandler(events.onError, ["SignalR: failed at parsing response: " + event.data + ". With error: " + error.message]);
connection.stop();
transportLogic.handleParseFailure(connection, event.data, error.message, onFailed);
return;
}

Expand Down

0 comments on commit 2bc7887

Please sign in to comment.