From 10edc4f186f7b837708df1e805071fd923c382f0 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 10 Nov 2018 22:05:15 +0100 Subject: [PATCH] net: always invoke after-write callback This is part of the streams API contract, and aligns network sockets with other streams in this respect. PR-URL: https://github.com/nodejs/node/pull/24291 Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Benjamin Gruenbaum Reviewed-By: Colin Ihrig Reviewed-By: Weijia Wang Reviewed-By: Matteo Collina Reviewed-By: Ruben Bridgewater --- lib/net.js | 2 ++ test/parallel/test-tls-invoke-queued.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) 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();