diff --git a/lib/net.js b/lib/net.js index 99dc76c8f3baf5..2cec3da58933f9 100644 --- a/lib/net.js +++ b/lib/net.js @@ -776,6 +776,8 @@ function afterWrite(status, handle, err) { // callback may come after call to destroy. if (self.destroyed) { debug('afterWrite destroyed'); + if (this.callback) + this.callback(null); return; } diff --git a/test/parallel/test-tls-invoke-queued.js b/test/parallel/test-tls-invoke-queued.js index 754b02ba0bae99..482ab847352793 100644 --- a/test/parallel/test-tls-invoke-queued.js +++ b/test/parallel/test-tls-invoke-queued.js @@ -40,8 +40,8 @@ const server = tls.createServer({ c.write('world!', null, common.mustCall(function() { c.destroy(); })); - // Data on next _write() will be written but callback will not be invoked - c.write(' gosh', null, common.mustNotCall()); + // Data on next _write() will be written, and the cb will still be invoked + c.write(' gosh', null, common.mustCall()); })); server.close();