From 970bbda9c884e36c7148a7d921d67c8253c13cdb Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sat, 20 Jun 2020 21:15:05 +0200 Subject: websockets: More robust in case of connection closures --- websockets/server.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/websockets/server.js b/websockets/server.js index 86307e6..b650ce1 100755 --- a/websockets/server.js +++ b/websockets/server.js @@ -63,6 +63,9 @@ wsServer=wsServer.ws("/*",{ linebuf=linebuf.slice(idx+1); } }); + stateobj.netconn.on("error",()=>{ + if(!stateobj.sock_closed)sock.close(); + }); }, message: (sock,data,isBinary)=>{ const stateobj=sock["tomsgdata"]; @@ -77,7 +80,8 @@ wsServer=wsServer.ws("/*",{ close: sock=>{ const stateobj=sock["tomsgdata"]; stateobj.sock_closed=true; - stateobj.netconn.end(); + try {stateobj.netconn.end();} + catch (e) {} } }); -- cgit v1.2.3-70-g09d2