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

Commit

Permalink
http2: client session destroy also destroys associated socket
Browse files Browse the repository at this point in the history
PR-URL: #64
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
kjin authored and jasnell committed May 31, 2017
1 parent 47d5b4f commit 28fda31
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
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 @@ -51,7 +51,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

0 comments on commit 28fda31

Please sign in to comment.