Skip to content

Commit c7ebf6e

Browse files
yhwangjasnell
authored andcommittedJun 5, 2017
http: suppress data event if req aborted
Re-enable test-http-abort-stream-end and put it into parallel category. Use system random port when calling server.listen() and fix eslint errors. After calling request.abort(), in order to avoid the buffered data to trigger the 'data' event, explicitly remove 'data' event listeners. PR-URL: #13260 Reviewed-By: Brian White <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 243643e commit c7ebf6e

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed
 

‎lib/_http_incoming.js

+3
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ function _addHeaderLine(field, value, dest) {
314314
IncomingMessage.prototype._dump = function _dump() {
315315
if (!this._dumped) {
316316
this._dumped = true;
317+
// If there is buffered data, it may trigger 'data' events.
318+
// Remove 'data' event listeners explicitly.
319+
this.removeAllListeners('data');
317320
this.resume();
318321
}
319322
};

‎test/disabled/test-http-abort-stream-end.js ‎test/parallel/test-http-abort-stream-end.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
const common = require('../common');
23+
require('../common');
2424
const assert = require('assert');
2525

2626
const http = require('http');
2727

28-
var maxSize = 1024;
29-
var size = 0;
28+
const maxSize = 1024;
29+
let size = 0;
3030

31-
var s = http.createServer(function(req, res) {
31+
const s = http.createServer(function(req, res) {
3232
this.close();
3333

3434
res.writeHead(200, {'Content-Type': 'text/plain'});
35-
for (var i = 0; i < maxSize; i++) {
35+
for (let i = 0; i < maxSize; i++) {
3636
res.write('x' + i);
3737
}
3838
res.end();
3939
});
4040

41-
var aborted = false;
42-
s.listen(common.PORT, function() {
43-
var req = http.get('http://localhost:' + common.PORT, function(res) {
41+
let aborted = false;
42+
s.listen(0, function() {
43+
const req = http.get('http://localhost:' + s.address().port, function(res) {
4444
res.on('data', function(chunk) {
4545
size += chunk.length;
4646
assert(!aborted, 'got data after abort');
@@ -51,8 +51,6 @@ s.listen(common.PORT, function() {
5151
}
5252
});
5353
});
54-
55-
req.end();
5654
});
5755

5856
process.on('exit', function() {

0 commit comments

Comments
 (0)
Please sign in to comment.