From c347e77647ed7c25d2eba4860ce62dbddaa46307 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 8ef0b6a6d7dad4..503946047d1e4f 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();