Skip to content

Commit cbbe44f

Browse files
committed
Merge pull request #351 from nkzawa/patch-6
wait for buffer to be drained before closing
2 parents 72c32ca + 866a56e commit cbbe44f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/socket.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,9 @@ Socket.prototype.close = function () {
586586
close();
587587
}
588588

589-
if (this.upgrading) {
589+
if (this.writeBuffer.length) {
590+
this.once('drain', close);
591+
} else if (this.upgrading) {
590592
// wait for upgrade to finish since we can't send packets while pausing a transport
591593
this.once('upgrade', cleanupAndClose);
592594
this.once('upgradeError', cleanupAndClose);

test/connection.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,18 @@ describe('connection', function() {
143143
}, 1200);
144144
});
145145
});
146+
147+
it('should send all buffered packets if closing is deferred', function(done) {
148+
var socket = new eio.Socket();
149+
socket.on('open', function() {
150+
socket.on('upgrading', function() {
151+
socket.send('hi');
152+
socket.close();
153+
}).on('close', function() {
154+
expect(socket.writeBuffer).to.have.length(0);
155+
done();
156+
});
157+
});
158+
});
146159
}
147160
});

0 commit comments

Comments
 (0)