From 7a548455ae95461be0a9d8e3e11dde9c51caef58 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 10 Nov 2018 21:11:17 +0100 Subject: [PATCH] tls: destroy TLS socket if StreamWrap is destroyed Previously, there was no mechanism in place that would have destroyed the TLS socket once the underlying socket had been closed. PR-URL: https://github.com/nodejs/node/pull/24290 Refs: https://github.com/nodejs/node/pull/24288 Refs: https://github.com/nodejs/node/pull/24075 Reviewed-By: James M Snell Reviewed-By: Daniel Bevenius Reviewed-By: Ouyang Yadong --- lib/_tls_wrap.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 36440ad4eaddf8..f00a9dce3fbc76 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -308,10 +308,12 @@ function TLSSocket(socket, opts) { // Wrap plain JS Stream into StreamWrap var wrap; - if ((socket instanceof net.Socket && socket._handle) || !socket) + if ((socket instanceof net.Socket && socket._handle) || !socket) { wrap = socket; - else + } else { wrap = new StreamWrap(socket); + wrap.once('close', () => this.destroy()); + } // Just a documented property to make secure sockets // distinguishable from regular ones.