-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: emit "write after end" errors in the next tick
This commit makes those errors caused by calling `net.Socket.write()` after sockets ending be emitted in the next tick. PR-URL: #24457 Fixes: #24111 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
2 changed files
with
27 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
const assert = require('assert'); | ||
const net = require('net'); | ||
|
||
const { mustCall } = common; | ||
|
||
// This test ensures those errors caused by calling `net.Socket.write()` | ||
// after sockets ending will be emitted in the next tick. | ||
const server = net.createServer(mustCall((socket) => { | ||
socket.end(); | ||
})).listen(() => { | ||
const client = net.connect(server.address().port, () => { | ||
let hasError = false; | ||
client.on('error', mustCall((err) => { | ||
hasError = true; | ||
server.close(); | ||
})); | ||
client.on('end', mustCall(() => { | ||
client.write('hello', mustCall()); | ||
assert(!hasError, 'The error should be emitted in the next tick.'); | ||
})); | ||
client.end(); | ||
}); | ||
}); |