Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jan 6, 2021
1 parent bbdf58e commit 126dd80
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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);
}
}
Expand Down
6 changes: 1 addition & 5 deletions test/parallel/test-stream-readable-data.js
Original file line number Diff line number Diff line change
@@ -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() {}

Expand Down

0 comments on commit 126dd80

Please sign in to comment.