GeezerVison is showing github.com — http2: fix subsequent end calls to not throw · nodejs/node@b61220e
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/http2/compat.js +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -466,14 +466,13 @@ class Http2ServerResponse extends Stream { |
466 | 466 | cb = encoding; |
467 | 467 | encoding = 'utf8'; |
468 | 468 | } |
| 469 | + if (stream === undefined || stream.finished === true) { |
| 470 | + return false; |
| 471 | + } |
469 | 472 | if (chunk !== null && chunk !== undefined) { |
470 | 473 | this.write(chunk, encoding); |
471 | 474 | } |
472 | 475 |
|
473 | | - if (stream === undefined) { |
474 | | - return; |
475 | | - } |
476 | | - |
477 | 476 | if (typeof cb === 'function') { |
478 | 477 | stream.once('finish', cb); |
479 | 478 | } |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-http2-compat-serverresponse-end.js +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
4 | 4 | const { mustCall, mustNotCall, hasCrypto, skip } = require('../common'); |
5 | 5 | if (!hasCrypto) |
6 | 6 | skip('missing crypto'); |
7 | | -const { strictEqual } = require('assert'); |
| 7 | +const { doesNotThrow, strictEqual } = require('assert'); |
8 | 8 | const { |
9 | 9 | createServer, |
10 | 10 | connect, |
@@ -19,6 +19,9 @@ const { |
19 | 19 | // but may be invoked repeatedly without throwing errors. |
20 | 20 | const server = createServer(mustCall((request, response) => { |
21 | 21 | strictEqual(response.closed, false); |
| 22 | + response.on('finish', mustCall(() => process.nextTick( |
| 23 | + mustCall(() => doesNotThrow(() => response.end('test', mustNotCall()))) |
| 24 | + ))); |
22 | 25 | response.end(mustCall(() => { |
23 | 26 | server.close(); |
24 | 27 | })); |
|