mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Back off comms reconnect attempts after prolonged failures
This commit is contained in:
parent
08794bad74
commit
0c227be02d
@ -18,7 +18,8 @@ RED.comms = (function() {
|
||||
|
||||
var errornotification = null;
|
||||
var clearErrorTimer = null;
|
||||
|
||||
var connectCountdownTimer = null;
|
||||
var connectCountdown = 10;
|
||||
var subscriptions = {};
|
||||
var ws;
|
||||
var pendingAuth = false;
|
||||
@ -82,14 +83,39 @@ RED.comms = (function() {
|
||||
}
|
||||
};
|
||||
ws.onclose = function() {
|
||||
if (reconnectAttempts > 5 && errornotification == null) {
|
||||
errornotification = RED.notify(RED._("notification.error",{message:RED._("notification.errors.lostConnection")}),"error",true);
|
||||
} else if (clearErrorTimer) {
|
||||
if (clearErrorTimer) {
|
||||
clearTimeout(clearErrorTimer);
|
||||
clearErrorTimer = null;
|
||||
}
|
||||
reconnectAttempts++;
|
||||
if (reconnectAttempts < 10) {
|
||||
setTimeout(connectWS,1000);
|
||||
if (reconnectAttempts > 5 && errornotification == null) {
|
||||
errornotification = RED.notify(RED._("notification.errors.lostConnection"),"error",true);
|
||||
}
|
||||
} else if (reconnectAttempts < 20) {
|
||||
setTimeout(connectWS,2000);
|
||||
} else {
|
||||
connectCountdown = 60;
|
||||
connectCountdownTimer = setInterval(function() {
|
||||
connectCountdown--;
|
||||
if (connectCountdown === 0) {
|
||||
errornotification.update(RED._("notification.errors.lostConnection"));
|
||||
clearInterval(connectCountdownTimer);
|
||||
connectWS();
|
||||
} else {
|
||||
var msg = RED._("notification.errors.lostConnectionReconnect",{time: connectCountdown})+' <a href="#">'+ RED._("notification.errors.lostConnectionTry")+'</a>';
|
||||
errornotification.update(msg);
|
||||
$(errornotification).find("a").click(function(e) {
|
||||
e.preventDefault();
|
||||
errornotification.update(RED._("notification.errors.lostConnection"));
|
||||
clearInterval(connectCountdownTimer);
|
||||
connectWS();
|
||||
})
|
||||
}
|
||||
},1000);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,14 @@ RED.notify = (function() {
|
||||
});
|
||||
};
|
||||
})();
|
||||
|
||||
n.update = (function() {
|
||||
var nn = n;
|
||||
return function(msg) {
|
||||
nn.innerHTML = msg;
|
||||
}
|
||||
})();
|
||||
|
||||
if (!fixed) {
|
||||
$(n).click((function() {
|
||||
var nn = n;
|
||||
|
@ -59,7 +59,9 @@
|
||||
|
||||
"error": "<strong>Error</strong>: __message__",
|
||||
"errors": {
|
||||
"lostConnection": "Lost connection to server",
|
||||
"lostConnection": "Lost connection to server, reconnecting...",
|
||||
"lostConnectionReconnect": "Lost connection to server, reconnecting in __time__s.",
|
||||
"lostConnectionTry": "Try now",
|
||||
"cannotAddSubflowToItself": "Cannot add subflow to itself",
|
||||
"cannotAddCircularReference": "Cannot add subflow - circular reference detected"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user