Title: stream.pipeline destroys writable stream when error is occurred · Issue #26311 · nodejs/node · GitHub
Open Graph Title: stream.pipeline destroys writable stream when error is occurred · Issue #26311 · nodejs/node
X Title: stream.pipeline destroys writable stream when error is occurred · Issue #26311 · nodejs/node
Description: Version: v11.10.0 Platform: Mac OS Darwin 16.7.0 Subsystem: stream, http stream.pipeline is helpful to handle error and interoperable to Promise. However, I found a behavior that is not suitable my usecase. I am creating a web server wit...
Open Graph Description: Version: v11.10.0 Platform: Mac OS Darwin 16.7.0 Subsystem: stream, http stream.pipeline is helpful to handle error and interoperable to Promise. However, I found a behavior that is not suitable my...
X Description: Version: v11.10.0 Platform: Mac OS Darwin 16.7.0 Subsystem: stream, http stream.pipeline is helpful to handle error and interoperable to Promise. However, I found a behavior that is not suitable my...
Opengraph URL: https://github.com/nodejs/node/issues/26311
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"stream.pipeline destroys writable stream when error is occurred","articleBody":"\u003c!--\r\nThank you for reporting a possible bug in Node.js.\r\n\r\nPlease fill in as much of the template below as you can.\r\n\r\nVersion: output of `node -v`\r\nPlatform: output of `uname -a` (UNIX), or version and 32 or 64-bit (Windows)\r\nSubsystem: if known, please specify the affected core module name\r\n\r\nIf possible, please provide code that demonstrates the problem, keeping it as\r\nsimple and free of external dependencies as you can.\r\n-->\r\n\r\n* **Version**:\r\nv11.10.0\r\n\r\n* **Platform**:\r\nMac OS Darwin 16.7.0\r\n\r\n* **Subsystem**:\r\nstream, http\r\n\r\nstream.pipeline is helpful to handle error and interoperable to Promise.\r\nHowever, I found a behavior that is not suitable my usecase.\r\n\r\nI am creating a web server with stream.pipeline. \r\nIf my readable stream emits an error like \"file not found\", I would like to send `error` response to my clients.\r\n\r\ncode example is as follows.\r\n\r\n```javascript\r\nconst fs = require('fs')\r\nconst http = require('http')\r\nconst { pipeline } = require('stream')\r\n\r\nconst server = http.createServer((req, res) => {\r\n const r = fs.createReadStream('./foo2.txt')\r\n pipeline(r, res, (err) => {\r\n if (err) {\r\n console.log(err) // No such file\r\n return res.end(\"error!!!\"); // write error response but this message is not shown.\r\n }\r\n })\r\n})\r\n\r\nserver.listen(9000)\r\n```\r\n\r\nI have investigated nodejs core, stream.pipeline destroys writable stream when error is occurred.\r\nhttps://github.com/nodejs/node/blob/master/lib/internal/streams/pipeline.js#L42\r\n\r\nso the above code cannot send error response. \r\n\r\n## Question\r\n\r\nIs this an expected behaviour? \r\nIn my understandings, writable stream should be closed anyway, but in this case, we would like to close writable stream manually.\r\n\r\nIn this situation, we need to create custom writable stream?\r\n\r\nI could send a PR to pass an option like `{ destroyOnError: false }` to avoid destory automatically.\r\n","author":{"url":"https://github.com/yosuke-furukawa","@type":"Person","name":"yosuke-furukawa"},"datePublished":"2019-02-26T06:13:08Z","url":"https://github.com/nodejs/node/issues/26311"}
| 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:9786617a-5462-c206-8feb-fcffb72b7a3c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 881C:39A2F9:BB0D7F:F9BC86:6AED3C00 |
| html-safe-nonce | d8a136b312e381929020c84de968d08d217cf71e1a6b1a2a0244fb6543c14b4f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODFDOjM5QTJGOTpCQjBEN0Y6RjlCQzg2OjZBRUQzQzAwIiwidmlzaXRvcl9pZCI6IjkwNDgyNjExMTk1Njk2NDA0NDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 626d995a7e55eb3e98f0d57b9ce0c79f8b3415bcca646cabc478539f6b9c3f14 |
| hovercard-subject-tag | issue:414448477 |
| 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/26311/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a7f92fe2ab2e138865740ab547be5ae1dba20e0504e6f3c76a47aa3a97c7c6eb/nodejs/node/issues/26311 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a7f92fe2ab2e138865740ab547be5ae1dba20e0504e6f3c76a47aa3a97c7c6eb/nodejs/node/issues/26311 |
| og:image:alt | Version: v11.10.0 Platform: Mac OS Darwin 16.7.0 Subsystem: stream, http stream.pipeline is helpful to handle error and interoperable to Promise. However, I found a behavior that is not suitable my... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yosuke-furukawa |
| 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