mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
http2: emit session connect on next tick
PR-URL: https://github.com/nodejs/node/pull/19842 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
This commit is contained in:
parent
f64aaba725
commit
2852521c49
@ -774,7 +774,7 @@ function setupHandle(socket, type, options) {
|
||||
// core will check for session.destroyed before progressing, this
|
||||
// ensures that those at l`east get cleared out.
|
||||
if (this.destroyed) {
|
||||
this.emit('connect', this, socket);
|
||||
process.nextTick(emit, this, 'connect', this, socket);
|
||||
return;
|
||||
}
|
||||
debug(`Http2Session ${sessionName(type)}: setting up session handle`);
|
||||
@ -816,7 +816,7 @@ function setupHandle(socket, type, options) {
|
||||
options.settings : {};
|
||||
|
||||
this.settings(settings);
|
||||
this.emit('connect', this, socket);
|
||||
process.nextTick(emit, this, 'connect', this, socket);
|
||||
}
|
||||
|
||||
// Emits a close event followed by an error event if err is truthy. Used
|
||||
|
@ -4,6 +4,9 @@ const { mustCall, hasCrypto, skip, expectsError } = require('../common');
|
||||
if (!hasCrypto)
|
||||
skip('missing crypto');
|
||||
const { createServer, connect } = require('http2');
|
||||
const { connect: netConnect } = require('net');
|
||||
|
||||
// check for session connect callback and event
|
||||
{
|
||||
const server = createServer();
|
||||
server.listen(0, mustCall(() => {
|
||||
@ -30,6 +33,28 @@ const { createServer, connect } = require('http2');
|
||||
}));
|
||||
}
|
||||
|
||||
// check for session connect callback on already connected socket
|
||||
{
|
||||
const server = createServer();
|
||||
server.listen(0, mustCall(() => {
|
||||
const { port } = server.address();
|
||||
|
||||
const onSocketConnect = () => {
|
||||
const authority = `http://localhost:${port}`;
|
||||
const createConnection = mustCall(() => socket);
|
||||
const options = { createConnection };
|
||||
connect(authority, options, mustCall(onSessionConnect));
|
||||
};
|
||||
|
||||
const onSessionConnect = (session) => {
|
||||
session.close();
|
||||
server.close();
|
||||
};
|
||||
|
||||
const socket = netConnect(port, mustCall(onSocketConnect));
|
||||
}));
|
||||
}
|
||||
|
||||
// check for https as protocol
|
||||
{
|
||||
const authority = 'https://localhost';
|
||||
|
Loading…
Reference in New Issue
Block a user