Skip to content

Revert "http2: fix end without read" #20832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ class Http2ServerRequest extends Readable {
stream[kRequest] = this;

// Pause the stream..
stream.pause();
stream.on('data', onStreamData);
stream.on('trailers', onStreamTrailers);
stream.on('end', onStreamEnd);
stream.on('error', onStreamError);
Expand Down Expand Up @@ -326,12 +328,8 @@ class Http2ServerRequest extends Readable {
_read(nread) {
const state = this[kState];
if (!state.closed) {
if (!state.didRead) {
state.didRead = true;
this[kStream].on('data', onStreamData);
} else {
process.nextTick(resumeStream, this[kStream]);
}
state.didRead = true;
process.nextTick(resumeStream, this[kStream]);
} else {
this.emit('error', new ERR_HTTP2_INVALID_STREAM());
}
Expand Down
12 changes: 5 additions & 7 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,11 @@ function onStreamClose(code) {
// Push a null so the stream can end whenever the client consumes
// it completely.
stream.push(null);
// If the client hasn't tried to consume the stream and there is no
// resume scheduled (which would indicate they would consume in the future),
// then just dump the incoming data so that the stream can be destroyed.
if (!stream[kState].didRead && !stream._readableState.resumeScheduled)
stream.resume();

// Same as net.
if (stream.readableLength === 0) {
stream.read(0);
}
}
}

Expand Down Expand Up @@ -1795,8 +1795,6 @@ class Http2Stream extends Duplex {
const ret = this[kHandle].trailers(headersList);
if (ret < 0)
this.destroy(new NghttpError(ret));
else
this[kMaybeDestroy]();
}

get closed() {
Expand Down
15 changes: 6 additions & 9 deletions test/parallel/test-http2-client-upload-reject.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ fs.readFile(loc, common.mustCall((err, data) => {
const server = http2.createServer();

server.on('stream', common.mustCall((stream) => {
// Wait for some data to come through.
setImmediate(() => {
stream.on('close', common.mustCall(() => {
assert.strictEqual(stream.rstCode, 0);
}));

stream.respond({ ':status': 400 });
stream.end();
});
stream.on('close', common.mustCall(() => {
assert.strictEqual(stream.rstCode, 0);
}));

stream.respond({ ':status': 400 });
stream.end();
}));

server.listen(0, common.mustCall(() => {
Expand Down
44 changes: 0 additions & 44 deletions test/parallel/test-http2-compat-client-upload-reject.js

This file was deleted.