const http = require('http')
const { host = '127.0.0.1', port = '8080' } = process.env
http
.createServer((_, res) => {
res.end('data')
})
.listen(port, () => {
const request = http
.request({
host,
port,
headers: { 'Connection': 'keep-alive' }
}, response => {
response
.on('data', () => {})
.on('end', () => {})
})
.end()
setTimeout(() => {
request.socket.destroy('Some error') // this line causes the error
}, 500)
})
It is reproduced 100% when running the code snippet above with node v12.16.3.
The behavior is inconsistent between node v12.16.2 and v12.16.3. I suppose, it would be ok in a next major-version. But, as it is a patch-version release, the error should not be thrown.
events.js:301
throw err; // Unhandled 'error' event
^
Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('Some error')
at Socket.emit (events.js:299:17)
at emitErrorNT (internal/streams/destroy.js:92:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'ERR_UNHANDLED_ERROR',
context: 'Some error'
}
Looks like the problem is caused by this commit https://github.com/nodejs/node/commit/225ddd5f425313908cf53d5d29fe746612d31e4c, it's exactly what @ronag described here. The socket has no 'error' event handler, so unhandled error is thrown, which can only be caught with process.on. Otherwise the process crashes.
I'm not sure if it's a heavy breaking change or the commit I mentioned should be reverted, as it can easily be fixed by adding an 'error' event handler to a socket. But it definitely caused me an hour or two of happy debug.
Please let me know if I can help with those todos in _http_client.js.
I will try to help out here later this week. Feel free to ping me if I forget.
@ronag should my colleague @pkozemirov and I do PR to fix this behaviour?
@vostrik go for it! I'll be happy to review
Please don't send messages in my email
On May 27, 2020 2:13 PM, "Pavel Vostrikov" notifications@github.com wrote:
@ronag https://github.com/ronag should my colleague @pkozemirov
https://github.com/pkozemirov and I do PR to fix this behaviour?—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/nodejs/node/issues/33434#issuecomment-634533373, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/ALWEDXY6OWEJII6HJ777CY3RTTKU5ANCNFSM4NC4YXLQ
.
@Baxtishodd You are subscribed to https://github.com/nodejs/node/issues/33434 and that's why are receiving mails. No one is mailing you.
Most helpful comment
I will try to help out here later this week. Feel free to ping me if I forget.