Skip to content

Commit c60ffe6

Browse files
rexagodcodebytere
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 b5f0fdb commit c60ffe6

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

lib/internal/http2/compat.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -698,11 +698,6 @@ class Http2ServerResponse extends Stream {
698698
const stream = this[kStream];
699699
const state = this[kState];
700700

701-
if ((state.closed || state.ending) &&
702-
state.headRequest === stream.headRequest) {
703-
return this;
704-
}
705-
706701
if (typeof chunk === 'function') {
707702
cb = chunk;
708703
chunk = null;
@@ -711,6 +706,14 @@ class Http2ServerResponse extends Stream {
711706
encoding = 'utf8';
712707
}
713708

709+
if ((state.closed || state.ending) &&
710+
state.headRequest === stream.headRequest) {
711+
if (typeof cb === 'function') {
712+
process.nextTick(cb);
713+
}
714+
return this;
715+
}
716+
714717
if (chunk !== null && chunk !== undefined)
715718
this.write(chunk, encoding);
716719

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

+6-6
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)