Skip to content
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

http2: fix subsequent end calls to not throw #15414

Closed
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
7 changes: 3 additions & 4 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,14 +458,13 @@ class Http2ServerResponse extends Stream {
cb = encoding;
encoding = 'utf8';
}
if (stream === undefined || stream.finished === true) {
return false;
}
if (chunk !== null && chunk !== undefined) {
this.write(chunk, encoding);
}

if (stream === undefined) {
return;
}

if (typeof cb === 'function') {
stream.once('finish', cb);
}
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-http2-compat-serverresponse-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const { mustCall, mustNotCall, hasCrypto, skip } = require('../common');
if (!hasCrypto)
skip('missing crypto');
const { strictEqual } = require('assert');
const { doesNotThrow, strictEqual } = require('assert');
const {
createServer,
connect,
Expand All @@ -19,6 +19,9 @@ const {
// but may be invoked repeatedly without throwing errors.
const server = createServer(mustCall((request, response) => {
strictEqual(response.closed, false);
response.on('finish', mustCall(() => process.nextTick(
mustCall(() => doesNotThrow(() => response.end('test', mustNotCall())))
Copy link
Member

@lpinca lpinca Sep 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit (feel free to ignore): mustCall seems redundant here. process.nextTick() callback is always called.

)));
response.end(mustCall(() => {
server.close();
}));
Expand Down