Skip to content

Commit

Permalink
http2: emit session connect on next tick
Browse files Browse the repository at this point in the history
Backport-PR-URL: #20456
PR-URL: #19842
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
  • Loading branch information
pietermees authored and MylesBorins committed May 15, 2018
1 parent 29643cc commit b54452d
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 @@ -734,7 +734,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 @@ -776,7 +776,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 @@ -5,6 +5,9 @@ if (!hasCrypto)
skip('missing crypto');
const { doesNotThrow, throws } = require('assert');
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 b54452d

Please sign in to comment.