-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: fix crash on OnStreamRead on Windows
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: #40764 PR-URL: #45878 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
4cdf000
commit 99c033e
Showing
2 changed files
with
51 additions
and
3 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,47 @@ | ||
'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'); | ||
})); | ||
})); | ||
} |