diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 9049a830f805e4..9bfdd4062fc762 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -310,10 +310,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.