mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
34af1f69b9
On Windows it's perfectly possible that the `uv_tcp_t` `read_cb` is called with an error and a null `uv_buf_t` if it corresponds to a `UV_HANDLE_ZERO_READ` read. Handle this case without crashing. Fixes: https://github.com/nodejs/node/issues/40764 PR-URL: https://github.com/nodejs/node/pull/45878 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { spawn } = require('child_process');
|
|
const net = require('net');
|
|
|
|
if (process.argv[2] === 'child') {
|
|
const server = net.createServer(common.mustCall());
|
|
server.listen(0, common.mustCall(() => {
|
|
process.send({ type: 'ready', data: { port: server.address().port } });
|
|
}));
|
|
} else {
|
|
const cp = spawn(process.execPath,
|
|
[__filename, 'child'],
|
|
{
|
|
stdio: ['ipc', 'inherit', 'inherit']
|
|
});
|
|
|
|
cp.on('exit', common.mustCall((code, signal) => {
|
|
assert.strictEqual(code, null);
|
|
assert.strictEqual(signal, 'SIGKILL');
|
|
}));
|
|
|
|
cp.on('message', common.mustCall((msg) => {
|
|
const { type, data } = msg;
|
|
assert.strictEqual(type, 'ready');
|
|
const port = data.port;
|
|
|
|
const conn = net.createConnection({
|
|
port,
|
|
onread: {
|
|
buffer: Buffer.alloc(65536),
|
|
callback: () => {},
|
|
}
|
|
});
|
|
|
|
conn.on('error', (err) => {
|
|
// Error emitted on Windows.
|
|
assert.strictEqual(err.code, 'ECONNRESET');
|
|
});
|
|
|
|
conn.on('connect', common.mustCall(() => {
|
|
cp.kill('SIGKILL');
|
|
}));
|
|
}));
|
|
}
|