Skip to content
This repository has been archived by the owner on Jul 6, 2018. It is now read-only.

http2: client session destroy also destroys associated socket #64

Closed
wants to merge 2 commits into from
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
13 changes: 10 additions & 3 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,16 @@ class Http2Session extends EventEmitter {
destroy() {
const state = this[kState];
const streams = state.streams;
const socket = this[kSocket];
if (state.destroyed) {
return;
}
state.destroyed = true;
if (!socket.destroyed) {
socket.destroy();
}
this[kSocket] = undefined;
this[kServer] = undefined;
timers.unenroll(this);
streams.forEach((value, key) => {
value[kSession] = undefined;
Expand Down Expand Up @@ -955,12 +964,10 @@ Object.defineProperties(Http2Session.prototype, {
// establishment of a new connection.
function socketDestroy(error) {
const session = this[kSession];
session.destroy();
session[kServer] = undefined;
session[kSocket] = undefined;
this[kServer] = undefined;
this.destroy = this[kDestroySocket];
this.destroy(error);
session.destroy();
}

function socketOnResume() {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http2-create-client-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const URL = url.URL;
let count = items.length;

const maybeClose = common.mustCall((client) => {
client.socket.destroy();
client.destroy();
if (--count === 0) {
setImmediate(() => server.close());
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http2-create-client-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ server.on('listening', common.mustCall(function() {
assert.strictEqual(body, data);
if (--expected === 0) {
server.close();
client.socket.destroy();
client.destroy();
}
}));
req.end();
Expand Down