Permalink
Browse files

ensure socket destruction in case of errors in upgrade processing

  • Loading branch information...
einaros committed May 20, 2012
1 parent 008da3b commit a00dfb374d216bc482917c666024e6e12ff7ddb1
Showing with 10 additions and 5 deletions.
  1. +10 −5 lib/WebSocketServer.js
View
@@ -214,7 +214,8 @@ function completeUpgrade(req, socket, upgradeHead, version, cb) {
socket.write(headers.concat('', '').join('\r\n'));
}
catch (e) {
- try { socket.end(); } catch (_) {}
+ // if the upgrade write fails, shut the connection down hard
+ try { socket.destroy(); } catch (e) {}
return;
}
socket.setTimeout(0);
@@ -250,7 +251,7 @@ function handleHixieUpgrade(req, socket, upgradeHead, cb) {
}
// setup handshake completion to run after client has been verified
- var self = this;
+ var self = this;
var onClientVerified = function() {
var protocol = req.headers['sec-websocket-protocol'];
@@ -292,7 +293,7 @@ function handleHixieUpgrade(req, socket, upgradeHead, cb) {
socket.write(md5.digest('binary'), 'binary');
}
catch (e) {
- try { socket.end(); } catch (_) {}
+ try { socket.destroy(); } catch (e) {}
return;
}
@@ -363,6 +364,7 @@ function handleHixieUpgrade(req, socket, upgradeHead, cb) {
return;
}
}
+ // no client verification required
onClientVerified();
}
@@ -373,7 +375,10 @@ function abortConnection(socket, code, name) {
'Content-type: text/html'
];
socket.write(response.concat('', '').join('\r\n'));
- socket.end();
}
- catch (e) {}
+ catch (e) { /* ignore errors - we've aborted this connection */ }
+ finally {
+ // ensure that an early aborted connection is shut down completely
+ try { socket.destroy(); } catch (e) {}
+ }
}

0 comments on commit a00dfb3

Please sign in to comment.