Skip to content

Commit

Permalink
net: always invoke after-write callback
Browse files Browse the repository at this point in the history
This is part of the streams API contract, and aligns
network sockets with other streams in this respect.

PR-URL: #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>
  • Loading branch information
addaleax authored and BridgeAR committed Nov 15, 2018
1 parent eeb5cc6 commit 10edc4f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-tls-invoke-queued.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 10edc4f

Please sign in to comment.