Skip to content

Commit 946418e

Browse files
committed
Merge pull request socketio#621 from einaros/master
Deals with a memleak in namespaces, and silently drops malformed websocket connections
2 parents 2bb60ac + 63043b3 commit 946418e

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

lib/manager.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,7 @@ Manager.prototype.onClientMessage = function (id, packet) {
468468

469469
Manager.prototype.onClientDisconnect = function (id, reason) {
470470
for (var name in this.namespaces) {
471-
if (this.roomClients[id][name]) {
472-
this.namespaces[name].handleDisconnect(id, reason);
473-
}
471+
this.namespaces[name].handleDisconnect(id, reason, typeof this.roomClients[id][name] !== 'undefined');
474472
}
475473

476474
this.onDisconnect(id);

lib/namespace.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ SocketNamespace.prototype.authorization = function (fn) {
224224
* @api private
225225
*/
226226

227-
SocketNamespace.prototype.handleDisconnect = function (sid, reason) {
227+
SocketNamespace.prototype.handleDisconnect = function (sid, reason, raiseOnDisconnect) {
228228
if (this.sockets[sid] && this.sockets[sid].readable) {
229-
this.sockets[sid].onDisconnect(reason);
229+
if (raiseOnDisconnect) this.sockets[sid].onDisconnect(reason);
230230
delete this.sockets[sid];
231231
}
232232
};

lib/transports/websocket/hybi-07-12.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ WebSocket.prototype.protocolVersion = '07-12';
9191
WebSocket.prototype.onSocketConnect = function () {
9292
var self = this;
9393

94-
if (this.req.headers.upgrade.toLowerCase() !== 'websocket') {
94+
if (typeof this.req.headers.upgrade === 'undefined' ||
95+
this.req.headers.upgrade.toLowerCase() !== 'websocket') {
9596
this.log.warn(this.name + ' connection invalid');
9697
this.end();
9798
return;

lib/transports/websocket/hybi-16.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ WebSocket.prototype.protocolVersion = '16';
9191
WebSocket.prototype.onSocketConnect = function () {
9292
var self = this;
9393

94-
if (this.req.headers.upgrade.toLowerCase() !== 'websocket') {
94+
if (typeof this.req.headers.upgrade === 'undefined' ||
95+
this.req.headers.upgrade.toLowerCase() !== 'websocket') {
9596
this.log.warn(this.name + ' connection invalid');
9697
this.end();
9798
return;

0 commit comments

Comments
 (0)