diff --git a/lib/_http_incoming.js b/lib/_http_incoming.js index 9151836ad83551..6e5aff1cc9c1f2 100644 --- a/lib/_http_incoming.js +++ b/lib/_http_incoming.js @@ -314,6 +314,9 @@ function _addHeaderLine(field, value, dest) { IncomingMessage.prototype._dump = function _dump() { if (!this._dumped) { this._dumped = true; + // If there is buffered data, it may trigger 'data' events. + // Remove 'data' event listeners explicitly. + this.removeAllListeners('data'); this.resume(); } }; diff --git a/test/disabled/test-http-abort-stream-end.js b/test/parallel/test-http-abort-stream-end.js similarity index 84% rename from test/disabled/test-http-abort-stream-end.js rename to test/parallel/test-http-abort-stream-end.js index f754e60300ff62..8f89aeffff2cd0 100644 --- a/test/disabled/test-http-abort-stream-end.js +++ b/test/parallel/test-http-abort-stream-end.js @@ -20,27 +20,27 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); const http = require('http'); -var maxSize = 1024; -var size = 0; +const maxSize = 1024; +let size = 0; -var s = http.createServer(function(req, res) { +const s = http.createServer(function(req, res) { this.close(); res.writeHead(200, {'Content-Type': 'text/plain'}); - for (var i = 0; i < maxSize; i++) { + for (let i = 0; i < maxSize; i++) { res.write('x' + i); } res.end(); }); -var aborted = false; -s.listen(common.PORT, function() { - var req = http.get('http://localhost:' + common.PORT, function(res) { +let aborted = false; +s.listen(0, function() { + const req = http.get('http://localhost:' + s.address().port, function(res) { res.on('data', function(chunk) { size += chunk.length; assert(!aborted, 'got data after abort'); @@ -51,8 +51,6 @@ s.listen(common.PORT, function() { } }); }); - - req.end(); }); process.on('exit', function() {