Socket: Reconnect if we miss server heartbeats

(imported from commit 52bd5ebdbec6e89f54dc67ad19a538dce910fe47)
This commit is contained in:
Zev Benjamin
2013-11-15 18:28:07 -05:00
parent 1562ba7439
commit 17cc606eee

View File

@@ -9,6 +9,7 @@ function Socket(url) {
this._requests = {};
this._connection_failures = 0;
this._reconnect_timeout_id = null;
this._heartbeat_timeout_id = null;
this._is_unloading = false;
$(window).on("unload", function () {
@@ -125,6 +126,18 @@ Socket.prototype = {
that._process_response(event.data.req_id, event.data.response);
};
sockjs.onheartbeat = function Socket__socjks_onheartbeat() {
if (that._heartbeat_timeout_id !== null) {
clearTimeout(that._heartbeat_timeout_id);
that._heartbeat_timeout_id = null;
}
that._heartbeat_timeout_id = setTimeout(function () {
that._heartbeat_timeout_id = null;
blueslip.info("Missed too many hearbeats");
that._try_to_reconnect();
}, 60000);
};
sockjs.onclose = function Socket__sockjs_onclose() {
if (that._is_unloading) {
return;
@@ -163,6 +176,11 @@ Socket.prototype = {
this._reconnect_timeout_id = null;
}
if (this._heartbeat_timeout_id !== null) {
clearTimeout(that._heartbeat_timeout_id);
this._heartbeat_timeout_id = null;
}
this._is_open = false;
this._is_authenticated = false;
this._is_reconnecting = true;