mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-01 07:33:12 +08:00
Close the socket corpus program's connection without a reset
evolving-let-socket-optional-reads.cjs ended the server's side of the connection as soon as it was accepted and closed the server while the client was still ending its own side. On macOS the client could then read ECONNRESET, under Node and the compiled program alike, and each reports the unhandled 'error' event in its own form. The server now ends its side once the client's end arrives, and the server closes when the client socket has closed. The program's output is unchanged.
This commit is contained in:
@@ -3,7 +3,12 @@
|
||||
// its first write: undefined short-circuits, the socket answers.
|
||||
const net = require('net');
|
||||
let c;
|
||||
const server = net.createServer((s) => s.end());
|
||||
// The server ends its side after the client's, and the server closes once
|
||||
// the client socket has closed, so neither side sees a reset.
|
||||
const server = net.createServer((s) => {
|
||||
s.resume();
|
||||
s.on('end', () => s.end());
|
||||
});
|
||||
function report(label) {
|
||||
console.log(label, c?.remoteAddress, c?.address()?.family, c?.remotePort > 0);
|
||||
}
|
||||
@@ -14,7 +19,8 @@ server.listen(0, '127.0.0.1', () => {
|
||||
c = net.connect(server.address().port, '127.0.0.1', () => {
|
||||
report('after');
|
||||
console.log('inside', c?.remoteAddress, c?.address()?.family);
|
||||
c.resume();
|
||||
c.on('close', () => server.close());
|
||||
c.end();
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user