diff --git a/lib/net.js b/lib/net.js index a9113ad5c680f9..9b139d28597b5c 100644 --- a/lib/net.js +++ b/lib/net.js @@ -790,6 +790,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();