GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http2: check if stream is not destroyed before sending trailers · nodejs/node@89fe9ed

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/http2
    • core.js
  • test/parallel
    • test-http2-compat-socket-destroy-delayed.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/http2/core.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/core.js
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,14 @@ function afterShutdown() {
14641464
}
14651465

14661466
function finishSendTrailers(stream, headersList) {
1467+
// The stream might be destroyed and in that case
1468+
// there is nothing to do.
1469+
// This can happen because finishSendTrailers is
1470+
// scheduled via setImmediate.
1471+
if (stream.destroyed) {
1472+
return;
1473+
}
1474+
14671475
stream[kState].flags &= ~STREAM_FLAGS_HAS_TRAILERS;
14681476

14691477
const ret = stream[kHandle].trailers(headersList);
Collapse file

‎test/parallel/test-http2-compat-socket-destroy-delayed.js‎

Copy file name to clipboard
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const { mustCall } = common;
5+
6+
if (!common.hasCrypto)
7+
common.skip('missing crypto');
8+
9+
const http2 = require('http2');
10+
const assert = require('assert');
11+
12+
const {
13+
HTTP2_HEADER_PATH,
14+
HTTP2_HEADER_METHOD,
15+
} = http2.constants;
16+
17+
// This tests verifies that calling `req.socket.destroy()` via
18+
// setImmediate does not crash.
19+
// Fixes https://github.com/nodejs/node/issues/22855.
20+
21+
const app = http2.createServer(mustCall((req, res) => {
22+
res.end('hello');
23+
setImmediate(() => req.socket.destroy());
24+
}));
25+
26+
app.listen(0, mustCall(() => {
27+
const session = http2.connect(`http://localhost:${app.address().port}`);
28+
const request = session.request({
29+
[HTTP2_HEADER_PATH]: '/',
30+
[HTTP2_HEADER_METHOD]: 'get'
31+
});
32+
request.once('response', mustCall((headers, flags) => {
33+
let data = '';
34+
request.on('data', (chunk) => { data += chunk; });
35+
request.on('end', mustCall(() => {
36+
assert.strictEqual(data, 'hello');
37+
session.close();
38+
app.close();
39+
}));
40+
}));
41+
request.end();
42+
}));

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.