From 126dd807c941322dabfbe134db62dc34eb662b0f Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 7 Jan 2021 00:03:39 +0100 Subject: [PATCH] fixup --- lib/_http_server.js | 2 +- lib/internal/streams/readable.js | 10 ++++++---- test/parallel/test-stream-readable-data.js | 6 +----- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/_http_server.js b/lib/_http_server.js index 9225ff06117859..d637472a83d7a7 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -803,7 +803,7 @@ function resOnFinish(req, res, socket, state, server) { // If the user never called req.read(), and didn't pipe() or // .resume() or .on('data'), then we call req._dump() so that the // bytes will be pulled off the wire. - if (!req._consuming && !req._readableState.resumeScheduled) + if (!req.readableDidRead) req._dump(); // Make sure the requestTimeout is cleared before finishing. diff --git a/lib/internal/streams/readable.js b/lib/internal/streams/readable.js index 9a8b8013dc56a9..7a765ab5a00c8a 100644 --- a/lib/internal/streams/readable.js +++ b/lib/internal/streams/readable.js @@ -205,7 +205,7 @@ function Readable(options) { Stream.call(this, options); destroyImpl.construct(this, () => { - if (this._readableState.didRead) { + if (this._readableState.needReadable) { maybeReadMore(this, this._readableState); } }); @@ -405,8 +405,6 @@ Readable.prototype.read = function(n) { const state = this._readableState; const nOrig = n; - state.didRead = true; - // If we're asking for more than the current hwm, then raise the hwm. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n); @@ -486,6 +484,7 @@ Readable.prototype.read = function(n) { // If the length is currently zero, then we *need* a readable event. if (state.length === 0) state.needReadable = true; + // Call internal read method this._read(state.highWaterMark); state.sync = false; @@ -524,8 +523,10 @@ Readable.prototype.read = function(n) { endReadable(this); } - if (ret !== null) + if (ret !== null) { + state.didRead = true; this.emit('data', ret); + } return ret; }; @@ -976,6 +977,7 @@ Readable.prototype.resume = function() { function resume(stream, state) { if (!state.resumeScheduled) { state.resumeScheduled = true; + state.didRead = true; process.nextTick(resume_, stream, state); } } diff --git a/test/parallel/test-stream-readable-data.js b/test/parallel/test-stream-readable-data.js index b017b2a4a25395..277adddde63584 100644 --- a/test/parallel/test-stream-readable-data.js +++ b/test/parallel/test-stream-readable-data.js @@ -1,15 +1,11 @@ 'use strict'; const common = require('../common'); -const assert = require('assert'); const { Readable } = require('stream'); const readable = new Readable({ - read() { - assert.strictEqual(readable.readableDidRead, true); - } + read() {} }); -assert.strictEqual(readable.readableDidRead, false); function read() {}