Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 429113e

Browse filesBrowse files
mmomtchevdanielleadams
authored andcommitted
http2: move events to the JSStreamSocket
When using a JSStreamSocket, the HTTP2Session constructor will replace the socket object http2 events should be attached to the JSStreamSocket object because the http2 session handle lives there Fixes: #35695 PR-URL: #35772 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
1 parent 06cc400 commit 429113e
Copy full SHA for 429113e

File tree

Expand file treeCollapse file tree

2 files changed

+61
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+61
-3
lines changed
Open diff view settings
Collapse file

‎lib/internal/http2/core.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/core.js
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,11 +3132,14 @@ function connect(authority, options, listener) {
31323132
}
31333133
}
31343134

3135-
socket.on('error', socketOnError);
3136-
socket.on('close', socketOnClose);
3137-
31383135
const session = new ClientHttp2Session(options, socket);
31393136

3137+
// ClientHttp2Session may create a new socket object
3138+
// when socket is a JSSocket (socket != kSocket)
3139+
// https://github.com/nodejs/node/issues/35695
3140+
session[kSocket].on('error', socketOnError);
3141+
session[kSocket].on('close', socketOnClose);
3142+
31403143
session[kAuthority] = `${options.servername || host}:${port}`;
31413144
session[kProtocol] = protocol;
31423145

Collapse file
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
const h2 = require('http2');
7+
const tls = require('tls');
8+
const fixtures = require('../common/fixtures');
9+
const { Duplex } = require('stream');
10+
11+
const server = h2.createSecureServer({
12+
key: fixtures.readKey('agent1-key.pem'),
13+
cert: fixtures.readKey('agent1-cert.pem')
14+
});
15+
16+
class JSSocket extends Duplex {
17+
constructor(socket) {
18+
super({ emitClose: true });
19+
socket.on('close', () => this.destroy());
20+
socket.on('data', (data) => this.push(data));
21+
this.socket = socket;
22+
}
23+
24+
_write(data, encoding, callback) {
25+
this.socket.write(data, encoding, callback);
26+
}
27+
28+
_read(size) {
29+
}
30+
31+
_final(cb) {
32+
cb();
33+
}
34+
}
35+
36+
server.listen(0, common.mustCall(function() {
37+
const socket = tls.connect({
38+
rejectUnauthorized: false,
39+
host: 'localhost',
40+
port: this.address().port,
41+
ALPNProtocols: ['h2']
42+
}, () => {
43+
const proxy = new JSSocket(socket);
44+
const client = h2.connect(`https://localhost:${this.address().port}`, {
45+
createConnection: () => proxy
46+
});
47+
const req = client.request();
48+
49+
setTimeout(() => socket.destroy(), 200);
50+
setTimeout(() => client.close(), 400);
51+
setTimeout(() => server.close(), 600);
52+
53+
req.on('close', common.mustCall(() => { }));
54+
});
55+
}));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.