Title: Stream emitting same error twice under certain circomstances · Issue #36053 · nodejs/node · GitHub
Open Graph Title: Stream emitting same error twice under certain circomstances · Issue #36053 · nodejs/node
X Title: Stream emitting same error twice under certain circomstances · Issue #36053 · nodejs/node
Description: Version: 12.18.1 and newer Platform: Darwin watson 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64 Subsystem: stream What steps will reproduce the bug? Run this code on Node....
Open Graph Description: Version: 12.18.1 and newer Platform: Darwin watson 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64 Subsystem: stream What steps will r...
X Description: Version: 12.18.1 and newer Platform: Darwin watson 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64 Subsystem: stream What steps will r...
Opengraph URL: https://github.com/nodejs/node/issues/36053
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Stream emitting same error twice under certain circomstances","articleBody":"* **Version**: 12.18.1 and newer\r\n* **Platform**: Darwin watson 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64\r\n* **Subsystem**: stream\r\n\r\n### What steps will reproduce the bug?\r\n\r\nRun this code on Node.js 12.18.1 or newer and notice how the error is emitted on `b` twice. On any older Node.js version it's only emitted once.\r\n\r\n```js\r\nconst { Readable, PassThrough, Writable, pipeline } = require('stream')\r\n\r\nconst a = new Readable({\r\n read () {\r\n this.destroy(new Error('foo'));\r\n }\r\n})\r\nconst b = new PassThrough()\r\nconst c = new Writable()\r\n\r\na.once('error', (err) =\u003e {\r\n console.log('emitting error on b')\r\n b.emit('error', err) // Note: you're not supposed to emit error manually!\r\n})\r\n\r\nb.on('error', (err) =\u003e {\r\n console.log('b got error:', err.message)\r\n})\r\n\r\npipeline(a.pipe(b), c, (err) =\u003e {\r\n console.log('end of pipeline, err:', err.message)\r\n})\r\n```\r\n\r\nIf I change `b.emit('error', err)` to `b.destroy(err)` the error goes away. Using `destroy` _is_ best practise and the user isn't supposed to emit `error` events manually on streams like in the above code. However, this was how we told users to do it previously, so a lot of code most likely exists in the wild expecting this to be possible and emitting the same error twice can have bad consequences.\r\n\r\nThoughts:\r\n1. It would be cool if we could warn users if they manually emitted an `error` event on a stream.\r\n1. It would be nice if we could make this odd behaviour go away even if the user emits `error` manually.\r\n\r\nThis regression was most likely introduced in #30869.\r\n\r\n\r\n","author":{"url":"https://github.com/watson","@type":"Person","name":"watson"},"datePublished":"2020-11-09T15:16:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/36053/node/issues/36053"}
| 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:cc004289-a074-da80-245b-02e974ec5982 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C472:36E597:283A617:3775499:6A4F5245 |
| html-safe-nonce | 9d0021c0450e4a98a520854cd8b18cc5d952ccb339fe6496429d966d32c6f894 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDcyOjM2RTU5NzoyODNBNjE3OjM3NzU0OTk6NkE0RjUyNDUiLCJ2aXNpdG9yX2lkIjoiMTA3OTA2NTQyMDU2NzEwNjExNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0027dc3dd66e38c333565b75d77749a113659445d41845df30a372a485c3c901 |
| hovercard-subject-tag | issue:739115450 |
| 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/36053/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5992f565c0e73505612ab70c9816d78f4f27b50eeb5e3887566a30c8a33f4e7e/nodejs/node/issues/36053 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5992f565c0e73505612ab70c9816d78f4f27b50eeb5e3887566a30c8a33f4e7e/nodejs/node/issues/36053 |
| og:image:alt | Version: 12.18.1 and newer Platform: Darwin watson 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64 Subsystem: stream What steps will r... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | watson |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| 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 | 4b249b445842943ed31549e027f57a8ade9881ed |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width