1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Stop sending messages to ws connections that have errored

Fixes #708
This commit is contained in:
Nick O'Leary 2015-07-30 22:09:01 +01:00
parent 6b03379e4e
commit 5193d7bddb

View File

@ -46,7 +46,7 @@ function start() {
var path = settings.httpAdminRoot || "/"; var path = settings.httpAdminRoot || "/";
path = (path.slice(0,1) != "/" ? "/":"") + path + (path.slice(-1) == "/" ? "":"/") + "comms"; path = (path.slice(0,1) != "/" ? "/":"") + path + (path.slice(-1) == "/" ? "":"/") + "comms";
wsServer = new ws.Server({server:server,path:path}); wsServer = new ws.Server({server:server,path:path});
wsServer.on('connection',function(ws) { wsServer.on('connection',function(ws) {
log.audit({event: "comms.open"}); log.audit({event: "comms.open"});
var pendingAuth = (settings.adminAuth != null); var pendingAuth = (settings.adminAuth != null);
@ -122,13 +122,13 @@ function start() {
log.warn(log._("comms.error",{message:err.toString()})); log.warn(log._("comms.error",{message:err.toString()}));
}); });
}); });
wsServer.on('error', function(err) { wsServer.on('error', function(err) {
log.warn(log._("comms.error-server",{message:err.toString()})); log.warn(log._("comms.error-server",{message:err.toString()}));
}); });
lastSentTime = Date.now(); lastSentTime = Date.now();
heartbeatTimer = setInterval(function() { heartbeatTimer = setInterval(function() {
var now = Date.now(); var now = Date.now();
if (now-lastSentTime > webSocketKeepAliveTime) { if (now-lastSentTime > webSocketKeepAliveTime) {
@ -167,6 +167,8 @@ function publishTo(ws,topic,data) {
try { try {
ws.send(msg); ws.send(msg);
} catch(err) { } catch(err) {
removeActiveConnection(ws);
removePendingConnection(ws);
log.warn(log._("comms.error-send",{message:err.toString()})); log.warn(log._("comms.error-send",{message:err.toString()}));
} }
} }