Skip to content

Commit 7f659a5

Browse files
perrin4869darrachequesne
authored andcommitted
[fix] Don't delete ws when closing the server (#444)
1 parent 60780e2 commit 7f659a5

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ Server.prototype.close = function () {
191191
if (this.ws) {
192192
debug('closing webSocketServer');
193193
this.ws.close();
194-
delete this.ws;
194+
// don't delete this.ws because it can be used again if the http server starts listening again
195195
}
196196
return this;
197197
};

test/server.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,27 @@ describe('server', function () {
543543
});
544544
});
545545

546+
it('should allow client reconnect after restarting (ws)', function (done) {
547+
var opts = { transports: ['websocket'] };
548+
var engine = listen(opts, function (port) {
549+
engine.httpServer.close();
550+
engine.httpServer.listen(port);
551+
552+
var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] });
553+
554+
engine.once('connection', function (conn) {
555+
setTimeout(function () {
556+
conn.close();
557+
}, 10);
558+
});
559+
560+
socket.once('close', function (reason) {
561+
expect(reason).to.be('transport close');
562+
done();
563+
});
564+
});
565+
});
566+
546567
it('should trigger when client closes', function (done) {
547568
var engine = listen({ allowUpgrades: false }, function (port) {
548569
var socket = new eioc.Socket('ws://localhost:%d'.s(port));

0 commit comments

Comments
 (0)