diff --git a/lib/server.js b/lib/server.js index 2b75f3544..60a9a438c 100644 --- a/lib/server.js +++ b/lib/server.js @@ -164,7 +164,9 @@ Server.prototype.prepare = function(req){ Server.prototype.close = function(){ debug('closing all open clients'); for (var i in this.clients) { - this.clients[i].close(); + if (this.clients.hasOwnProperty(i)) { + this.clients[i].close(); + } } return this; }; diff --git a/test/server.js b/test/server.js index 3645cb837..55ae63b79 100644 --- a/test/server.js +++ b/test/server.js @@ -933,6 +933,19 @@ describe('server', function () { }); }); }); + + it('should not crash when messing with Object prototype', function(done){ + Object.prototype.foo = 'bar'; + var engine = listen({ allowUpgrades: true }, function (port) { + var socket = new eioc.Socket('ws://localhost:%d'.s(port)); + socket.on('open', function () { + engine.close(); + setTimeout(function(){ + done(); + }, 100); + }); + }); + }); }); describe('messages', function () {