René's URL Explorer Experiment


Title: Problems with cooperation between http and pipeline/"for await" · Issue #38262 · nodejs/node · GitHub

Open Graph Title: Problems with cooperation between http and pipeline/"for await" · Issue #38262 · nodejs/node

X Title: Problems with cooperation between http and pipeline/"for await" · Issue #38262 · nodejs/node

Description: Is your feature request related to a problem? Please describe. Problem is that "for await" and pipeline destroy source stream on error ("for await" also on break) but destroying http request removes possibility to send meaningful respons...

Open Graph Description: Is your feature request related to a problem? Please describe. Problem is that "for await" and pipeline destroy source stream on error ("for await" also on break) but destroying http request remove...

X Description: Is your feature request related to a problem? Please describe. Problem is that "for await" and pipeline destroy source stream on error ("for await" also on break) but destroying...

Opengraph URL: https://github.com/nodejs/node/issues/38262

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Problems with cooperation between http and pipeline/\"for await\"","articleBody":"**Is your feature request related to a problem? Please describe.**\r\n\r\nProblem is that \"for await\" and pipeline destroy source stream on error (\"for await\" also on break) but destroying http request removes possibility to send meaningful response to client.\r\n\r\nExample with \"for await\" (body length limiting):\r\n``` js\r\nlet http = require(\"http\");\r\n\r\nlet server = http.createServer(async function(req, res)\r\n{\r\n\ttry\r\n\t{\r\n\t\tlet len = 0;\r\n\t\tfor await (let chunk of req)\r\n\t\t{\r\n\t\t\tlen += chunk.length;\r\n\t\t\tif(len > 2) throw \"payload too large\";\r\n\t\t}\r\n\t\tres.end(\"ok\");\r\n\t}\r\n\tcatch(err)\r\n\t{\r\n\t\tconsole.log(\"server log:\", err);\r\n\t\tres.end(err);\r\n\t}\r\n});\r\n\r\n(async function()\r\n{\r\n\tawait new Promise(resolve => server.listen(8888, resolve));\r\n\tlet req = http.request({ port: 8888, method: \"post\" });\r\n\treq.end(\"abc\");\r\n\ttry\r\n\t{\r\n\t\tlet res = await new Promise((resolve, reject) => req.on(\"response\", resolve).on(\"error\", reject));\r\n\t\tlet str = \"\";\r\n\t\tfor await (let chunk of res) str += chunk;\r\n\t\tconsole.log(\"client received:\", str);\r\n\t}\r\n\tcatch(err)\r\n\t{\r\n\t\tconsole.log(\"client got unexpected error:\", err);\r\n\t}\r\n\tserver.close();\r\n}());\r\n```\r\n\r\nPossible output:\r\n```\r\nserver log: payload too large\r\nclient got unexpected error: Error: socket hang up\r\n    at connResetException (node:internal/errors:642:14)\r\n    at Socket.socketOnEnd (node:_http_client:486:23)\r\n    at Socket.emit (node:events:381:22)\r\n    at endReadableNT (node:internal/streams/readable:1307:12)\r\n    at processTicksAndRejections (node:internal/process/task_queues:81:21) {\r\n  code: 'ECONNRESET'\r\n}\r\n```\r\n\r\nPossible solution is to not use pipeline but pipe instead. But this requires additional handling like to do `req.unpipe` and `req.resume` to avoid problems for example:\r\n``` js\r\nlet http = require(\"http\");\r\nlet { PassThrough } = require(\"stream\");\r\n\r\nlet server = http.createServer(async function(req, res)\r\n{\r\n\ttry\r\n\t{\r\n\t\tlet len = 0;\r\n\t\tfor await (let chunk of req.pipe(new PassThrough()))\r\n\t\t{\r\n\t\t\tlen += chunk.length;\r\n\t\t\tif(len > 2) throw \"payload too large\";\r\n\t\t}\r\n\t\tres.end(\"ok\");\r\n\t}\r\n\tcatch(err)\r\n\t{\r\n\t\tconsole.log(\"server log:\", err);\r\n\t\treq.unpipe();\r\n\t\treq.resume();\r\n\t\treq.on(\"end\", () => res.end(err));\r\n\t}\r\n});\r\n\r\n(async function()\r\n{\r\n\tawait new Promise(resolve => server.listen(8888, resolve));\r\n\tlet req = http.request({ port: 8888, method: \"post\" });\r\n\treq.end(\"abc\");\r\n\ttry\r\n\t{\r\n\t\tlet res = await new Promise((resolve, reject) => req.on(\"response\", resolve).on(\"error\", reject));\r\n\t\tlet str = \"\";\r\n\t\tfor await (let chunk of res) str += chunk;\r\n\t\tconsole.log(\"client received:\", str);\r\n\t}\r\n\tcatch(err)\r\n\t{\r\n\t\tconsole.log(\"client got unexpected error:\", err);\r\n\t}\r\n\tserver.close();\r\n}());\r\n```\r\n\r\nThis neglected solution with forgotten `unpipe` and `resume` cases EPIPE sometimes or stops after first iteration when using keepalive `Agent`:\r\n\r\n``` js\r\nlet http = require(\"http\");\r\nlet { PassThrough } = require(\"stream\");\r\n\r\nlet server = http.createServer(async function(req, res)\r\n{\r\n\ttry\r\n\t{\r\n\t\tlet len = 0;\r\n\t\tfor await (let chunk of req.pipe(new PassThrough()))\r\n\t\t{\r\n\t\t\tlen += chunk.length;\r\n\t\t\tif(len > 2) throw \"payload too large\";\r\n\t\t}\r\n\t\tres.end(\"ok\");\r\n\t}\r\n\tcatch(err)\r\n\t{\r\n\t\tres.end(err);\r\n\t}\r\n});\r\n\r\n(async function()\r\n{\r\n\tawait new Promise(resolve => server.listen(8888, resolve));\r\n\tlet agent = new http.Agent({ keepAlive: true });\r\n\tlet data = Buffer.alloc(1000000);\r\n\tfor(let i = 0; ; i++)\r\n\t{\r\n\t\tconsole.log(i);\r\n\t\tlet req = http.request({ port: 8888, method: \"post\"/*, agent*/ }).end(data);\r\n\t\tlet res = await new Promise((resolve, reject) => req.on(\"response\", resolve).on(\"error\", reject));\r\n\t\tlet str = \"\";\r\n\t\tfor await (let chunk of res) str += chunk;\r\n\t\tconsole.log(str);\r\n\t}\r\n}());\r\n```\r\n\r\n```\r\n2572\r\npayload too large\r\n2573\r\nnode:internal/process/promises:245\r\n          triggerUncaughtException(err, true /* fromPromise */);\r\n          ^\r\n\r\nError: write EPIPE\r\n    at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16) {\r\n  errno: -32,\r\n  code: 'EPIPE',\r\n  syscall: 'write'\r\n}\r\n```\r\n\r\n**Describe the solution you'd like**\r\n\r\nPipe is too leak-prone for language which builds on GC. But a fixed and more comfortable pipeline and \"for await\" have unexpected consequences for http streams.\r\n\r\nWould be great to have some options for the `pipeline` function to not destroy streams but instead dump them to the end in case of error (so one can send response when the pipeline ends). Or http request could have the option that `destroy` would just dump stream to end (and only then actually send response) instead of causing EPIPE or similar faults at client side.\r\n","author":{"url":"https://github.com/misos1","@type":"Person","name":"misos1"},"datePublished":"2021-04-16T19:03:20Z","url":"https://github.com/nodejs/node/issues/38262"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:90f455c3-f2da-3430-4952-c53bff88e443
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE56C:20309E:7E038E:A50ADB:6AED364F
html-safe-noncef46a357934c92792955eb207d31b74e17c4f26046ccda0880cf8807d5ce17fc2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNTZDOjIwMzA5RTo3RTAzOEU6QTUwQURCOjZBRUQzNjRGIiwidmlzaXRvcl9pZCI6IjQ1NzczODYzNDI2NzU5ODU5OTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacdb3ba1a5277ef747cd0fa07deaae5222a35172a57fa130c156a458ca859f6885
hovercard-subject-tagissue:860091545
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/38262/issue_layout
twitter:imagehttps://opengraph.githubassets.com/16ea08b75c6aaf5d36363303fbbab14944f9d33873ee6703c7a0161bdd495e9b/nodejs/node/issues/38262
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/16ea08b75c6aaf5d36363303fbbab14944f9d33873ee6703c7a0161bdd495e9b/nodejs/node/issues/38262
og:image:altIs your feature request related to a problem? Please describe. Problem is that "for await" and pipeline destroy source stream on error ("for await" also on break) but destroying http request remove...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemisos1
hostnamegithub.com
expected-hostnamegithub.com
None26c92a9388ddfad3fa88d132b5d5f0b4747030233dcc4e5efb05f1cbae152184
turbo-cache-controlno-preview
go-importgithub.com/nodejs/node git https://github.com/nodejs/node.git
octolytics-dimension-user_id9950313
octolytics-dimension-user_loginnodejs
octolytics-dimension-repository_id27193779
octolytics-dimension-repository_nwonodejs/node
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id27193779
octolytics-dimension-repository_network_root_nwonodejs/node
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasec629ad99c254d306375fc8354d04321c2c362236
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/nodejs/node/issues/38262#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F38262
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F38262
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=nodejs%2Fnode
Reloadhttps://github.com/nodejs/node/issues/38262
Reloadhttps://github.com/nodejs/node/issues/38262
Reloadhttps://github.com/nodejs/node/issues/38262
nodejshttps://github.com/nodejs
nodehttps://github.com/nodejs/node
Codehttps://github.com/nodejs/node
Issues656 (656)https://github.com/nodejs/node/issues
Pull requests665 (665)https://github.com/nodejs/node/pulls
Actionshttps://github.com/nodejs/node/actions
Projectshttps://github.com/nodejs/node/projects
Security and qualityhttps://github.com/nodejs/node/security
Insightshttps://github.com/nodejs/node/pulse
https://github.com/nodejs/node
New issuehttps://github.com/login?return_to=https://github.com/nodejs/node/issues/38262
New issuehttps://github.com/login?return_to=https://github.com/nodejs/node/issues/38262
Problems with cooperation between http and pipeline/"for await"https://github.com/nodejs/node/issues/38262#top
confirmed-bugIssues and PRs for confirmed bugs.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22confirmed-bug%22
httpIssues and PRs related to the http subsystem.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22http%22
promisesIssues and PRs related to ECMAScript promises.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22promises%22
streamIssues and PRs related to Node.js streams.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22stream%22
https://github.com/misos1
misos1https://github.com/misos1
on Apr 16, 2021https://github.com/nodejs/node/issues/38262#issue-860091545
misos1https://github.com/misos1
on Apr 16, 2021https://github.com/nodejs/node/issues/38262#event-4606454472
misos1https://github.com/misos1
on Apr 16, 2021https://github.com/nodejs/node/issues/38262#event-4606462932
Ayase-252https://github.com/Ayase-252
feature requestIssues requesting new Node.js features.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22feature%20request%22
on Apr 17, 2021https://github.com/nodejs/node/issues/38262#event-4607646442
https://github.com/benjamingr
benjamingrhttps://github.com/benjamingr
on Apr 17, 2021https://github.com/nodejs/node/issues/38262#issuecomment-821836630
benjamingrhttps://github.com/benjamingr
confirmed-bugIssues and PRs for confirmed bugs.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22confirmed-bug%22
httpIssues and PRs related to the http subsystem.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22http%22
promisesIssues and PRs related to ECMAScript promises.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22promises%22
streamIssues and PRs related to Node.js streams.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22stream%22
on Apr 17, 2021https://github.com/nodejs/node/issues/38262#event-4608033016
https://github.com/benjamingr
benjamingrhttps://github.com/benjamingr
on Apr 17, 2021https://github.com/nodejs/node/issues/38262#issuecomment-821836705
@ronaghttps://github.com/ronag
@mcollinahttps://github.com/mcollina
Ayase-252https://github.com/Ayase-252
feature requestIssues requesting new Node.js features.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22feature%20request%22
on Apr 17, 2021https://github.com/nodejs/node/issues/38262#event-4608034305
https://github.com/benjamingr
benjamingrhttps://github.com/benjamingr
on Apr 17, 2021https://github.com/nodejs/node/issues/38262#issuecomment-821844872
https://github.com/benjamingr
benjamingrhttps://github.com/benjamingr
on Apr 17, 2021https://github.com/nodejs/node/issues/38262#issuecomment-821845233
https://github.com/benjamingr
benjamingrhttps://github.com/benjamingr
on Apr 17, 2021https://github.com/nodejs/node/issues/38262#issuecomment-821846186
https://github.com/ronag
ronaghttps://github.com/ronag
on Apr 19, 2021https://github.com/nodejs/node/issues/38262#issuecomment-822227277
https://github.com/benjamingr
benjamingrhttps://github.com/benjamingr
on Apr 19, 2021https://github.com/nodejs/node/issues/38262#issuecomment-822272801
@ronaghttps://github.com/ronag
https://github.com/ronag
ronaghttps://github.com/ronag
on Apr 19, 2021https://github.com/nodejs/node/issues/38262#issuecomment-822323903
https://github.com/benjamingr
benjamingrhttps://github.com/benjamingr
on Apr 19, 2021https://github.com/nodejs/node/issues/38262#issuecomment-822361177
@ronaghttps://github.com/ronag
https://github.com/ronag
ronaghttps://github.com/ronag
on Apr 19, 2021https://github.com/nodejs/node/issues/38262#issuecomment-822412716
https://github.com/nodejs/undici/blob/main/lib/core/util.js#L125https://github.com/nodejs/undici/blob/main/lib/core/util.js#L125
https://github.com/benjamingr
benjamingrhttps://github.com/benjamingr
on Apr 19, 2021https://github.com/nodejs/node/issues/38262#issuecomment-822417334
@ronaghttps://github.com/ronag
https://github.com/ronag
ronaghttps://github.com/ronag
on Apr 19, 2021https://github.com/nodejs/node/issues/38262#issuecomment-822426291
@ronaghttps://github.com/ronag
https://github.com/benjamingr
benjamingrhttps://github.com/benjamingr
on Apr 19, 2021https://github.com/nodejs/node/issues/38262#issuecomment-822427649
https://github.com/misos1
misos1https://github.com/misos1
on Apr 19, 2021https://github.com/nodejs/node/issues/38262#issuecomment-822574445
3d480dchttps://github.com/nodejs/node/commit/3d480dcf4c270cbf5a3acef08fc6b8d25576411b
#26311https://github.com/nodejs/node/issues/26311
https://github.com/RafaelGSS
RafaelGSShttps://github.com/RafaelGSS
on Dec 9, 2021https://github.com/nodejs/node/issues/38262#issuecomment-990110539
@misos1https://github.com/misos1
https://github.com/RafaelGSS
RafaelGSShttps://github.com/RafaelGSS
on Dec 9, 2021https://github.com/nodejs/node/issues/38262#issuecomment-990305346
#38505https://github.com/nodejs/node/pull/38505
mcollinahttps://github.com/mcollina
completedhttps://github.com/nodejs/node/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Dec 9, 2021https://github.com/nodejs/node/issues/38262#event-5744271560
https://github.com/misos1
misos1https://github.com/misos1
on Dec 10, 2021https://github.com/nodejs/node/issues/38262#issuecomment-991233190
#38505https://github.com/nodejs/node/pull/38505
https://github.com/RafaelGSS
RafaelGSShttps://github.com/RafaelGSS
on Dec 11, 2021https://github.com/nodejs/node/issues/38262#issuecomment-991408892
Sign up for freehttps://github.com/signup?return_to=https://github.com/nodejs/node/issues/38262
Sign in to commenthttps://github.com/login?return_to=https://github.com/nodejs/node/issues/38262
confirmed-bugIssues and PRs for confirmed bugs.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22confirmed-bug%22
httpIssues and PRs related to the http subsystem.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22http%22
promisesIssues and PRs related to ECMAScript promises.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22promises%22
streamIssues and PRs related to Node.js streams.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22stream%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.