Skip to content

Commit fdcd489

Browse files
rexagodaddaleax
authored andcommitted
http2: always call callback on Http2ServerResponse#end
Fixes: #28001 PR-URL: #33911 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent e199fc5 commit fdcd489

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

lib/internal/http2/compat.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -709,11 +709,6 @@ class Http2ServerResponse extends Stream {
709709
const stream = this[kStream];
710710
const state = this[kState];
711711

712-
if ((state.closed || state.ending) &&
713-
state.headRequest === stream.headRequest) {
714-
return this;
715-
}
716-
717712
if (typeof chunk === 'function') {
718713
cb = chunk;
719714
chunk = null;
@@ -722,6 +717,14 @@ class Http2ServerResponse extends Stream {
722717
encoding = 'utf8';
723718
}
724719

720+
if ((state.closed || state.ending) &&
721+
state.headRequest === stream.headRequest) {
722+
if (typeof cb === 'function') {
723+
process.nextTick(cb);
724+
}
725+
return this;
726+
}
727+
725728
if (chunk !== null && chunk !== undefined)
726729
this.write(chunk, encoding);
727730

test/parallel/test-http2-compat-serverresponse-end.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ const {
2525
// but callback will only be called once
2626
const server = createServer(mustCall((request, response) => {
2727
response.end('end', 'utf8', mustCall(() => {
28-
response.end(mustNotCall());
28+
response.end(mustCall());
2929
process.nextTick(() => {
30-
response.end(mustNotCall());
30+
response.end(mustCall());
3131
server.close();
3232
});
3333
}));
3434
response.on('finish', mustCall(() => {
35-
response.end(mustNotCall());
35+
response.end(mustCall());
3636
}));
37-
response.end(mustNotCall());
37+
response.end(mustCall());
3838
}));
3939
server.listen(0, mustCall(() => {
4040
let data = '';
@@ -294,7 +294,7 @@ const {
294294
}));
295295
response.end('data', mustCall(() => {
296296
strictEqual(finished, false);
297-
response.end('data', mustNotCall());
297+
response.end('data', mustCall());
298298
}));
299299
}));
300300
server.listen(0, mustCall(() => {
@@ -328,7 +328,7 @@ const {
328328
// Should be able to respond to HEAD with just .end
329329
const server = createServer(mustCall((request, response) => {
330330
response.end('data', mustCall());
331-
response.end(mustNotCall());
331+
response.end(mustCall());
332332
}));
333333
server.listen(0, mustCall(() => {
334334
const { port } = server.address();

0 commit comments

Comments
 (0)