Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup: account for destroy before connect
  • Loading branch information
apapirovski committed Apr 27, 2018
commit 08fa98cd04d9507a73b30444a44b815e4ef7abd5
8 changes: 5 additions & 3 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ function requestOnConnect(headers, options) {

// At this point, the stream should have already been destroyed during
// the session.destroy() method. Do nothing else.
if (session.destroyed)
if (session === undefined || session.destroyed)
return;

// If the session was closed while waiting for the connect, destroy
Expand Down Expand Up @@ -1842,11 +1842,13 @@ class Http2Stream extends Duplex {
const code = err != null ?
NGHTTP2_INTERNAL_ERROR : (state.rstCode || NGHTTP2_NO_ERROR);

const hasHandle = handle !== undefined;

if (!this.closed)
closeStream(this, code);
closeStream(this, code, hasHandle);
this.push(null);

if (handle !== undefined) {
if (hasHandle) {
handle.destroy();
session[kState].streams.delete(id);
} else {
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-http2-client-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,21 @@ const Countdown = require('../common/countdown');
req.on('error', () => {});
}));
}

// test destroy before connect
{
const server = h2.createServer();
server.on('stream', common.mustNotCall());

server.listen(0, common.mustCall(() => {
const client = h2.connect(`http://localhost:${server.address().port}`);

server.on('connection', common.mustCall(() => {
server.close();
client.close();
}));

const req = client.request();
req.destroy();
}));
}