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

Commit ea162f1

Browse files
committed
http2: client session destroy also destroys associated socket
1 parent 7e862f3 commit ea162f1

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

lib/internal/http2/core.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,14 @@ class Http2Session extends EventEmitter {
435435
destroy() {
436436
const state = this[kState];
437437
const streams = state.streams;
438+
const socket = this[kSocket];
439+
if (state.destroyed) {
440+
return;
441+
}
438442
state.destroyed = true;
443+
socket.destroy();
444+
this[kSocket] = undefined;
445+
this[kServer] = undefined;
439446
timers.unenroll(this);
440447
streams.forEach((value, key) => {
441448
value[kSession] = undefined;
@@ -955,12 +962,10 @@ Object.defineProperties(Http2Session.prototype, {
955962
// establishment of a new connection.
956963
function socketDestroy(error) {
957964
const session = this[kSession];
958-
session.destroy();
959-
session[kServer] = undefined;
960-
session[kSocket] = undefined;
961965
this[kServer] = undefined;
962966
this.destroy = this[kDestroySocket];
963967
this.destroy(error);
968+
session.destroy();
964969
}
965970

966971
function socketOnResume() {

test/parallel/test-http2-create-client-connect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const URL = url.URL;
2828
let count = items.length;
2929

3030
const maybeClose = common.mustCall((client) => {
31-
client.socket.destroy();
31+
client.destroy();
3232
if (--count === 0) {
3333
setImmediate(() => server.close());
3434
}

test/parallel/test-http2-create-client-session.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ server.on('listening', common.mustCall(function() {
4747
assert.strictEqual(body, data);
4848
if (--expected === 0) {
4949
server.close();
50-
client.socket.destroy();
50+
client.destroy();
5151
}
5252
}));
5353
req.end();

0 commit comments

Comments
 (0)