Title: Update http module to return "408 - Request timeout"- when closing idle TCP connections. · Issue #38890 · nodejs/node · GitHub
Open Graph Title: Update http module to return "408 - Request timeout"- when closing idle TCP connections. · Issue #38890 · nodejs/node
X Title: Update http module to return "408 - Request timeout"- when closing idle TCP connections. · Issue #38890 · nodejs/node
Description: Is your feature request related to a problem? YES Currently, http implementation results in random HTTP errors, as a result of race conditions when closing idle connections. Node closes idle TCP connections after 5 seconds (configurable ...
Open Graph Description: Is your feature request related to a problem? YES Currently, http implementation results in random HTTP errors, as a result of race conditions when closing idle connections. Node closes idle TCP co...
X Description: Is your feature request related to a problem? YES Currently, http implementation results in random HTTP errors, as a result of race conditions when closing idle connections. Node closes idle TCP co...
Opengraph URL: https://github.com/nodejs/node/issues/38890
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Update http module to return \"408 - Request timeout\"- when closing idle TCP connections.","articleBody":"**Is your feature request related to a problem? YES**\r\n\r\nCurrently, http implementation results in random HTTP errors, as a result of race conditions when closing idle connections.\r\n\r\nNode closes idle TCP connections after 5 seconds (configurable using `server.keepAliveTimeout`),\r\nresulting in a race conditions described at: [https://nodejs.org/api/http.html#http_request_reusedsocket]()\r\n\r\nThis documentation proposes request might be retried when receiving a `ECONNRESET` error, and that's what\r\nbrowsers do. However, this is not applicable when working with API Gateways, which can't close a downstream\r\nconnection (shared by multiple services) when an upstream connection is closed.\r\nInstead, Gateways return a 503 error code when an upstream connection is closed, resulting in a HTTP error.\r\nAdditional info [here](https://medium.com/@phylake/why-idle-timeouts-matter-1b3f7d4469fe).\r\n\r\nThe solution would be to configure `server.keepAliveTimeout` to be larger than the client. But Chrome keeps idle connections open for 5 to 6 minutes (according to [link](https://bugs.chromium.org/p/chromium/issues/detail?id=27400), up to 10 minutes). Using such a long timeout in the cloud might not be a good idea.\r\n\r\n**Proposed solution**\r\n[RFC7231#6.5.7](https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.7) and [Mozilla](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) specify that servers MAY/SHOULD send a `408 – Request Timeout` response when closing idle connections, _even without a previous request from the server_. This would make any further request (if any) to receive a 408 error and would be automatically retried by the browser.\r\n\r\nNotice that, when using CORS, 408 response MUST include CORS headers (`Access-Control-Allow-Origin: *`).\r\n\r\nCurrently, there's no simple way to update http module, to return a 408 error when closing idle connections.\r\n\r\nI propose updating http module, to allow handling the idle-connection close event. Eg:\r\n```\r\nserver.on('idle', socket => {\r\n socket.write('408 - Request timeout\\r\\nConnection: close\\r\\nAccess-Control-Allow-Origin: *\\r\\n\\r\\n');\r\n socket.close();\r\n});\r\n```\r\n\r\n**Alternative solution**\r\nThis feature could also be an option, when creating the HTTP server. Eg:\r\n```\r\nhttp.createServer({ reply408WhenClosingIdleConnections: true }, handler);\r\n```\r\n","author":{"url":"https://github.com/gpra","@type":"Person","name":"gpra"},"datePublished":"2021-06-01T15:08:40Z","url":"https://github.com/nodejs/node/issues/38890"}
| 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:7e347fa4-68eb-4df7-c0bb-dd1d99bfd039 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B0BC:2F339D:C1B142:1022A2C:6AED3C65 |
| html-safe-nonce | 74e07f19fac2a1f4dd05f2f22d05e23d7ad752e94abe45f55f1c424fce1cf1e2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMEJDOjJGMzM5RDpDMUIxNDI6MTAyMkEyQzo2QUVEM0M2NSIsInZpc2l0b3JfaWQiOiIxMjU2NDU2NTI0OTA5MDY3MzY1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 717590553b4543539b617d36e19d69f078f6b40fc8170670859dc5d8fe4f5297 |
| hovercard-subject-tag | issue:908396163 |
| 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/38890/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dd14dade1752887ac3018dfd168d48521bf1cf6ee3b4a71aff42c8feef1203a6/nodejs/node/issues/38890 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dd14dade1752887ac3018dfd168d48521bf1cf6ee3b4a71aff42c8feef1203a6/nodejs/node/issues/38890 |
| og:image:alt | Is your feature request related to a problem? YES Currently, http implementation results in random HTTP errors, as a result of race conditions when closing idle connections. Node closes idle TCP co... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gpra |
| hostname | github.com |
| expected-hostname | github.com |
| None | 26c92a9388ddfad3fa88d132b5d5f0b4747030233dcc4e5efb05f1cbae152184 |
| 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 | c629ad99c254d306375fc8354d04321c2c362236 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width