mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 14:25:18 +00:00

Currently the writable side of the socket is closed as soon as `UV_EOF` is read regardless of the state of the socket. This allows the handle to be closed before `'end'` is emitted and thus `'close'` can be emitted before `'end'` if the socket is paused. This commit prevents the handle from being closed until `'end'` is emitted ensuring the correct order of events. PR-URL: https://github.com/nodejs/node/pull/19241 Fixes: https://github.com/nodejs/node/issues/19166 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
32 lines
639 B
JavaScript
32 lines
639 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
const net = require('net');
|
|
|
|
const server = net.createServer();
|
|
|
|
server.on('connection', (socket) => {
|
|
let endEmitted = false;
|
|
|
|
socket.once('readable', () => {
|
|
setTimeout(() => {
|
|
socket.read();
|
|
}, common.platformTimeout(100));
|
|
});
|
|
socket.on('end', () => {
|
|
endEmitted = true;
|
|
});
|
|
socket.on('close', () => {
|
|
assert(endEmitted);
|
|
server.close();
|
|
});
|
|
socket.end('foo');
|
|
});
|
|
|
|
server.listen(common.mustCall(() => {
|
|
const socket = net.createConnection(server.address().port, () => {
|
|
socket.end('foo');
|
|
});
|
|
}));
|