Skip to content

Commit

Permalink
http2: emit session connect on next tick
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
pietermees authored and mcollina committed Apr 11, 2018
1 parent f64aaba commit 2852521
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions test/parallel/test-http2-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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';
Expand Down

0 comments on commit 2852521

Please sign in to comment.