Title: Calling `socket.destroy()` causes unhandled error in v12.16.3 · Issue #33434 · nodejs/node · GitHub
Open Graph Title: Calling `socket.destroy()` causes unhandled error in v12.16.3 · Issue #33434 · nodejs/node
X Title: Calling `socket.destroy()` causes unhandled error in v12.16.3 · Issue #33434 · nodejs/node
Description: Version: v12.16.3 Platform: Linux 73659abd8e3f 4.19.76-linuxkit #1 SMP Thu Oct 17 19:31:58 UTC 2019 x86_64 GNU/Linux Subsystem: _http_agent, _http_client What steps will reproduce the bug? const http = require('http') const { host = '127...
Open Graph Description: Version: v12.16.3 Platform: Linux 73659abd8e3f 4.19.76-linuxkit #1 SMP Thu Oct 17 19:31:58 UTC 2019 x86_64 GNU/Linux Subsystem: _http_agent, _http_client What steps will reproduce the bug? const ht...
X Description: Version: v12.16.3 Platform: Linux 73659abd8e3f 4.19.76-linuxkit #1 SMP Thu Oct 17 19:31:58 UTC 2019 x86_64 GNU/Linux Subsystem: _http_agent, _http_client What steps will reproduce the bug? const ht...
Opengraph URL: https://github.com/nodejs/node/issues/33434
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Calling `socket.destroy()` causes unhandled error in v12.16.3","articleBody":"* **Version**: v12.16.3\r\n* **Platform**: Linux 73659abd8e3f 4.19.76-linuxkit #1 SMP Thu Oct 17 19:31:58 UTC 2019 x86_64 GNU/Linux\r\n* **Subsystem**: _http_agent, _http_client\r\n\r\n### What steps will reproduce the bug?\r\n\r\n```javascript\r\nconst http = require('http')\r\nconst { host = '127.0.0.1', port = '8080' } = process.env\r\n\r\nhttp\r\n .createServer((_, res) => {\r\n res.end('data')\r\n })\r\n .listen(port, () => {\r\n const request = http\r\n .request({\r\n host,\r\n port,\r\n headers: { 'Connection': 'keep-alive' }\r\n }, response => {\r\n response\r\n .on('data', () => {})\r\n .on('end', () => {})\r\n })\r\n .end()\r\n setTimeout(() => {\r\n request.socket.destroy('Some error') // this line causes the error\r\n }, 500)\r\n })\r\n\r\n```\r\n### How often does it reproduce? Is there a required condition?\r\n\r\nIt is reproduced 100% when running the code snippet above with node v12.16.3.\r\n\r\n### What is the expected behavior?\r\n\r\nThe 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.\r\n\r\n### What do you see instead?\r\n\r\n```\r\nevents.js:301\r\n throw err; // Unhandled 'error' event\r\n ^\r\n\r\nError [ERR_UNHANDLED_ERROR]: Unhandled error. ('Some error')\r\n at Socket.emit (events.js:299:17)\r\n at emitErrorNT (internal/streams/destroy.js:92:8)\r\n at processTicksAndRejections (internal/process/task_queues.js:84:21) {\r\n code: 'ERR_UNHANDLED_ERROR',\r\n context: 'Some error'\r\n}\r\n```\r\n\r\n### Additional information\r\n\r\nLooks like the problem is caused by this commit https://github.com/nodejs/node/commit/225ddd5f425313908cf53d5d29fe746612d31e4c, it's exactly what @ronag described [here](https://github.com/nodejs/node/commit/225ddd5f425313908cf53d5d29fe746612d31e4c#diff-e3bc37430eb078ccbafe3aa3b570c91aR619). The socket has no `'error'` event handler, so [unhandled error is thrown](https://github.com/nodejs/node/blob/225ddd5f425313908cf53d5d29fe746612d31e4c/lib/events.js#L287), which can only be caught with `process.on`. Otherwise the process crashes.\r\n\r\nI'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.\r\n\r\nPlease let me know if I can help with those todos in `_http_client.js`.","author":{"url":"https://github.com/pkozemirov","@type":"Person","name":"pkozemirov"},"datePublished":"2020-05-16T12:29:03Z","url":"https://github.com/nodejs/node/issues/33434"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9d23c35b-24dc-7fab-855e-78d3ed55099f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9EBA:137C1B:53B7AE:6CF325:6AED2814 |
| html-safe-nonce | aa316b31a93292d697920426396fff3599ed510a90b8011949f306715344277f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RUJBOjEzN0MxQjo1M0I3QUU6NkNGMzI1OjZBRUQyODE0IiwidmlzaXRvcl9pZCI6IjIwNjYwNzk0ODEwNzA0MzAyMjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 64d69f8b38512ee03ae6fccf90564d8524a539f131e7ee03c4401cb0e1aa1268 |
| hovercard-subject-tag | issue:619462407 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/33434/issue_layout |
| twitter:image | https://opengraph.githubassets.com/67031d45368bbd61728c8190702dd90a391502df9aa4e63469f28347e98891e6/nodejs/node/issues/33434 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/67031d45368bbd61728c8190702dd90a391502df9aa4e63469f28347e98891e6/nodejs/node/issues/33434 |
| og:image:alt | Version: v12.16.3 Platform: Linux 73659abd8e3f 4.19.76-linuxkit #1 SMP Thu Oct 17 19:31:58 UTC 2019 x86_64 GNU/Linux Subsystem: _http_agent, _http_client What steps will reproduce the bug? const ht... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pkozemirov |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9d95365dda0576efe9b71f45807595e396bd0ca9286fba5367a05048e6ddf8f2 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 98b41fa4b5635ceb45a4c54320fced73817ff290 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width