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 <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Anna Henningsen 2018-11-10 22:05:15 +01:00
parent 3212f77ac6
commit c347e77647
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
2 changed files with 4 additions and 2 deletions

View File

@ -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;
}

View File

@ -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();