Skip to content

Commit

Permalink
Merge pull request socketio#297 from lpinca/close/data-request
Browse files Browse the repository at this point in the history
polling: correctly abort the ongoing data request when closing transport
  • Loading branch information
rauchg committed Jan 3, 2015
2 parents 1e36bfe + 9526e0d commit 6699cd2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/transports/polling.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ Polling.prototype.onDataRequest = function (req, res) {
cleanup();
}

req.abort = cleanup;
req.on('close', onClose);
req.on('data', onData);
req.on('end', onEnd);
Expand Down Expand Up @@ -265,9 +264,8 @@ Polling.prototype.doClose = function (fn) {
debug('closing');

if (this.dataReq) {
// FIXME: should we do this?
debug('aborting ongoing data request');
this.dataReq.abort();
this.dataReq.destroy();
}

if (this.writable) {
Expand Down
21 changes: 21 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,27 @@ describe('server', function () {
});
});

it('should abort the polling data request if it is ' +
'in progress', function (done) {
var engine = listen({ transports: [ 'polling' ] }, function (port) {
var socket = new eioc.Socket('http://localhost:%d'.s(port));

engine.on('connection', function (conn) {
var onDataRequest = conn.transport.onDataRequest;
conn.transport.onDataRequest = function (req, res) {
engine.httpServer.close(done);
onDataRequest.call(conn.transport, req, res);
req.removeAllListeners();
conn.close();
};
});

socket.on('open', function () {
socket.send('test');
});
});
});

// tests https://github.com/LearnBoost/engine.io-client/issues/207
// websocket test, transport error
it('should trigger transport close before open for ws', function(done){
Expand Down

0 comments on commit 6699cd2

Please sign in to comment.