Title: Network request fails after event loop is blocked for a few seconds (regression in v20) · Issue #54293 · nodejs/node · GitHub
Open Graph Title: Network request fails after event loop is blocked for a few seconds (regression in v20) · Issue #54293 · nodejs/node
X Title: Network request fails after event loop is blocked for a few seconds (regression in v20) · Issue #54293 · nodejs/node
Description: Version v20.16.0 Platform Darwin MacBook.my.network 23.6.0 Darwin Kernel Version 23.6.0: Fri Jul 5 17:54:52 PDT 2024; root:xnu-10063.141.1~2/RELEASE_ARM64_T8103 arm64 Subsystem http What steps will reproduce the bug? Block the event loop...
Open Graph Description: Version v20.16.0 Platform Darwin MacBook.my.network 23.6.0 Darwin Kernel Version 23.6.0: Fri Jul 5 17:54:52 PDT 2024; root:xnu-10063.141.1~2/RELEASE_ARM64_T8103 arm64 Subsystem http What steps will...
X Description: Version v20.16.0 Platform Darwin MacBook.my.network 23.6.0 Darwin Kernel Version 23.6.0: Fri Jul 5 17:54:52 PDT 2024; root:xnu-10063.141.1~2/RELEASE_ARM64_T8103 arm64 Subsystem http What steps will...
Opengraph URL: https://github.com/nodejs/node/issues/54293
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Network request fails after event loop is blocked for a few seconds (regression in v20)","articleBody":"### Version\r\n\r\nv20.16.0\r\n\r\n### Platform\r\n\r\n```text\r\nDarwin MacBook.my.network 23.6.0 Darwin Kernel Version 23.6.0: Fri Jul 5 17:54:52 PDT 2024; root:xnu-10063.141.1~2/RELEASE_ARM64_T8103 arm64\r\n```\r\n\r\n\r\n### Subsystem\r\n\r\nhttp\r\n\r\n### What steps will reproduce the bug?\r\n\r\n1. Block the event loop for 10 seconds via a long-running operation\r\n2. Make a network request via `http.request()`\r\n\r\nCode example:\r\n\r\n```js\r\nconst http = require(\"node:http\");\r\n\r\nconst makePostRequest = () =>\r\n new Promise((resolve, reject) => {\r\n const onResponse = (res) => {\r\n let data = \"\";\r\n\r\n res.on(\"data\", (chunk) => {\r\n data += chunk;\r\n });\r\n\r\n res.on(\"end\", () => resolve(data));\r\n };\r\n\r\n const req = http.request(\r\n \"http://127.0.0.1:3000/\",\r\n { method: \"POST\" },\r\n onResponse,\r\n );\r\n\r\n req.on(\"error\", (e) => reject(e));\r\n\r\n req.end();\r\n });\r\n\r\nconst makeRequests = async () => {\r\n await makePostRequest();\r\n\r\n console.log(\"First request worked\");\r\n\r\n const timestamp = Date.now();\r\n\r\n // Block the event loop for 10 seconds\r\n while (Date.now() \u003c timestamp + 10000);\r\n\r\n // Enable the following line and it will work:\r\n // await new Promise((resolve) => setTimeout(resolve, 10));\r\n\r\n await makePostRequest();\r\n\r\n console.log(\"It crashes before it gets here\");\r\n};\r\n\r\nconst server = http.createServer((req, res) => {\r\n console.log(\"Request received\");\r\n res.statusCode = 200;\r\n res.setHeader(\"Content-Type\", \"text/plain\");\r\n res.end(\"Hello world!\\n\");\r\n});\r\n\r\nserver.listen(3000, \"127.0.0.1\", () => {\r\n console.log(\"Server up\");\r\n\r\n makeRequests();\r\n});\r\n\r\n```\r\n\r\n### How often does it reproduce? Is there a required condition?\r\n\r\nReproduces always.\r\n\r\n### What is the expected behavior? Why is that the expected behavior?\r\n\r\nThe network request works.\r\n\r\n### What do you see instead?\r\n\r\n1. The network request fails with `ECONNRESET`.\r\n2. The network request does not reach the server.\r\n\r\nLog from running the code above:\r\n\r\n```\r\nServer up\r\nRequest received\r\nFirst request worked\r\nnode:internal/process/promises:391\r\n triggerUncaughtException(err, true /* fromPromise */);\r\n ^\r\n\r\nError: read ECONNRESET\r\n at TCP.onStreamRead (node:internal/stream_base_commons:218:20) {\r\n errno: -54,\r\n code: 'ECONNRESET',\r\n syscall: 'read'\r\n}\r\n\r\nNode.js v20.16.0\r\n\r\nProcess finished with exit code 1\r\n```\r\n\r\n### Additional information\r\n\r\nThis is a regression. The code works on Node.js 18. It fails on Node.js 20.\r\n\r\nIf we wait for 10ms before running the network request, it works.","author":{"url":"https://github.com/nikwen","@type":"Person","name":"nikwen"},"datePublished":"2024-08-09T22:41:24Z","url":"https://github.com/nodejs/node/issues/54293"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:3d02464a-6773-c48e-88dd-faddec69455f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CA82:1FD7D4:417322:580718:6B061E6B |
| html-safe-nonce | 64c6064c396a5d573f4a4c5e5f01c3e13e071773eb639023b533fdcf3568f2cb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTgyOjFGRDdENDo0MTczMjI6NTgwNzE4OjZCMDYxRTZCIiwidmlzaXRvcl9pZCI6IjI0NjI2Mzg2MzkwNTQ5ODY4NTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a09399b0abcb8401a2f1b39dd38c918bae45f00dc84a054097db17845d229940 |
| hovercard-subject-tag | issue:2458753115 |
| 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/54293/issue_layout |
| twitter:image | https://opengraph.githubassets.com/895d66bb27f01069b0aab43c76cff4cef4a375d68703de01de469316bba4285d/nodejs/node/issues/54293 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/895d66bb27f01069b0aab43c76cff4cef4a375d68703de01de469316bba4285d/nodejs/node/issues/54293 |
| og:image:alt | Version v20.16.0 Platform Darwin MacBook.my.network 23.6.0 Darwin Kernel Version 23.6.0: Fri Jul 5 17:54:52 PDT 2024; root:xnu-10063.141.1~2/RELEASE_ARM64_T8103 arm64 Subsystem http What steps will... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nikwen |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9a7c5824b75ea2ec5e3de73a483229c7bb9f32a774ffd401f010dd9bacf1483d |
| 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 | b25c3080e84402f75431d8dc7a96b2635219cec7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width