From 112c9f4b81566cc1f1edfef018a86e3c9b8b44e6 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 13 Jul 2017 10:08:00 -0700 Subject: [PATCH] http2: avoid unnecessary closure --- lib/internal/http2/core.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 5379d17c0e..1d095b8c55 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -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 { @@ -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