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

Commit

Permalink
http2: avoid unnecessary closure
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Jul 13, 2017
1 parent 4be7a08 commit 112c9f4
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,21 @@ function submitShutdown(options) {
}
}

function finishSessionDestroy(socket) {
if (!socket.destroyed)
socket.destroy();

// Destroy the handle
const handle = this[kHandle];
if (handle !== undefined) {
handle.destroy();
debug(`[${sessionName(this[kType])}] nghttp2session handle destroyed`);
}

this.emit('close');
debug(`[${sessionName(this[kType])}] nghttp2session destroyed`);
}

// Upon creation, the Http2Session takes ownership of the socket. The session
// may not be ready to use immediately if the socket is not yet fully connected.
class Http2Session extends EventEmitter {
Expand Down Expand Up @@ -919,27 +934,14 @@ class Http2Session extends EventEmitter {

// Disassociate from the socket and server
const socket = this[kSocket];
socket.pause();
// socket.pause();
delete this[kSocket];
delete this[kServer];

state.destroyed = true;
state.destroying = false;

setImmediate(() => {
if (!socket.destroyed)
socket.destroy();

// Destroy the handle
const handle = this[kHandle];
if (handle !== undefined) {
handle.destroy();
debug(`[${sessionName(this[kType])}] nghttp2session handle destroyed`);
}

this.emit('close');
debug(`[${sessionName(this[kType])}] nghttp2session destroyed`);
});
setImmediate(finishSessionDestroy.bind(this, socket));
}

// Graceful or immediate shutdown of the Http2Session. Graceful shutdown
Expand Down

0 comments on commit 112c9f4

Please sign in to comment.