Title: Recent behavior change of buffered write callbacks · Issue #31317 · nodejs/node · GitHub
Open Graph Title: Recent behavior change of buffered write callbacks · Issue #31317 · nodejs/node
X Title: Recent behavior change of buffered write callbacks · Issue #31317 · nodejs/node
Description: As requested by @mcollina in #31179 (comment) I'm opening this issue to discuss the possibility of reverting a recent behavior change of writable streams. writable.write() takes an optional callback which, quoting the documentation, is a...
Open Graph Description: As requested by @mcollina in #31179 (comment) I'm opening this issue to discuss the possibility of reverting a recent behavior change of writable streams. writable.write() takes an optional callbac...
X Description: As requested by @mcollina in #31179 (comment) I'm opening this issue to discuss the possibility of reverting a recent behavior change of writable streams. writable.write() takes an optional cal...
Opengraph URL: https://github.com/nodejs/node/issues/31317
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Recent behavior change of buffered write callbacks","articleBody":"As requested by @mcollina in https://github.com/nodejs/node/pull/31179#issuecomment-572183520 I'm opening this issue to discuss the possibility of reverting a recent behavior change of writable streams.\r\n\r\n[writable.write()](https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback) takes an optional callback which, quoting the documentation, is a\r\n\r\n\u003e Callback for when this chunk of data is flushed\r\n\r\nThe documentation further clarifies the callback behavior as follows:\r\n\r\n\u003e The `writable.write()` method writes some data to the stream, and calls the\r\n\u003e supplied `callback` once the data has been fully handled. If an error occurs,\r\n\u003e the callback _may or may not_ be called with the error as its first argument.\r\n\u003e To reliably detect write errors, add a listener for the `'error'` event. If\r\n\u003e callback is called with an error, it will be called before the `'error'` event\r\n\u003e is emitted.\r\n\r\nThis is quite accurate and inline with the actual implementation. There can only be a single write at time so if `writable.write()` is called while a write is in progress that write is buffered. If the stream errors or is destroyed the callbacks of buffered writes are not called.\r\n\r\nIn https://github.com/nodejs/node/pull/29028 and then in https://github.com/nodejs/node/pull/30596 this behavior was changed to call the callbacks of buffered writes with an error.\r\n\r\nIn my opinion this change was not need or better not justified by a specific issue. From what I've gathered (correct me if I am wrong) the main reason behind the change was that code like this\r\n\r\n```js\r\nawait for (const chunk of src) {\r\n new Promise(function(resolve, reject) {\r\n dst.write(chunk, err =\u003e err ? reject(err) : resolve());\r\n });\r\n}\r\n```\r\n\r\ncould result in a promise that is never settled, but the destination stream in the example does not buffer writes so the callback is always called.\r\n\r\nI think this change creates more problems than it solves:\r\n\r\n- Not all callbacks must be called. A lot of callbacks are only called in response of a specific event / operation. If that event or operation never occurred its associated callback should not be called. This depends on case-by-case basis. In this specific case if the callback is called it makes me think that buffered writes are attempted even after a stream errors or is destroyed and this is not true even after https://github.com/nodejs/node/pull/30596.\r\n- AFAIK no issues have been created? about buffered write callbacks not being called on error in all these years so I think the original behavior is not broken.\r\n- There are some side effects like https://github.com/nodejs/node/issues/30841 or https://github.com/nodejs/node/pull/31179#issuecomment-570890897.\r\n- It is hard to adapt user land code to this new behavior. For example `net.Socket` buffered write callbacks are now called with an error if a write error occurs. Doing the same on Node.js \u003c 13 will be hard and hacky for userland libs. They should wait until Node.js 12 goes EOL to have the same behavior across all supported Node.js versions.\r\n\r\nRefs: https://github.com/nodejs/node/pull/29028\r\nRefs: https://github.com/nodejs/node/pull/30596\r\nRefs: https://github.com/nodejs/node/pull/31179\r\n","author":{"url":"https://github.com/lpinca","@type":"Person","name":"lpinca"},"datePublished":"2020-01-11T15:58:40.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/31317/node/issues/31317"}
| 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:a1172aff-5549-550e-b1d5-10d63915e052 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC3C:1F16:66531DE:9175878:6A50F0A3 |
| html-safe-nonce | 9fc1d36dbadd3369c02a91ab7d61691e12055fba8a6a12ede3658d92d9d5f940 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzNDOjFGMTY6NjY1MzFERTo5MTc1ODc4OjZBNTBGMEEzIiwidmlzaXRvcl9pZCI6IjEzMzU3NDkwOTg3MjEwNDY2OTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | fc57522f6821ec7c7716e6838ca5e9ee5f3c275da0ace250e6fd6c7787d25b9d |
| hovercard-subject-tag | issue:548446545 |
| 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/31317/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b414a6faf78c4bf4bfb8c24adc44d810a8829334b0876229d5b1f75915cce6f6/nodejs/node/issues/31317 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b414a6faf78c4bf4bfb8c24adc44d810a8829334b0876229d5b1f75915cce6f6/nodejs/node/issues/31317 |
| og:image:alt | As requested by @mcollina in #31179 (comment) I'm opening this issue to discuss the possibility of reverting a recent behavior change of writable streams. writable.write() takes an optional callbac... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lpinca |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5266e58c17a510c403505cc811606465e90a881d2007ee7df1c4800d5c659838 |
| 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 | 5ec60191a48933536a90c8a19f47142fcd0d4739 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width