diff options
Diffstat (limited to 'lib/internal/wrap_js_stream.js')
-rw-r--r-- | lib/internal/wrap_js_stream.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/internal/wrap_js_stream.js b/lib/internal/wrap_js_stream.js index e6de433676..7ca7ff8bf4 100644 --- a/lib/internal/wrap_js_stream.js +++ b/lib/internal/wrap_js_stream.js @@ -68,6 +68,12 @@ class JSStreamWrap extends Socket { if (this._handle) this._handle.emitEOF(); }); + // Some `Stream` don't pass `hasError` parameters when closed. + stream.once('close', () => { + // Errors emitted from `stream` have also been emitted to this instance + // so that we don't pass errors to `destroy()` again. + this.destroy(); + }); super({ handle, manualStart: true }); this.stream = stream; @@ -188,6 +194,14 @@ class JSStreamWrap extends Socket { doClose(cb) { const handle = this._handle; + // When sockets of the "net" module destroyed, they will call + // `this._handle.close()` which will also emit EOF if not emitted before. + // This feature makes sockets on the other side emit "end" and "close" + // even though we haven't called `end()`. As `stream` are likely to be + // instances of `net.Socket`, calling `stream.destroy()` manually will + // avoid issues that don't properly close wrapped connections. + this.stream.destroy(); + setImmediate(() => { // Should be already set by net.js assert.strictEqual(this._handle, null); |