Title: `stream.pipeline()` can both throw synchronously and invoke the callback reporting success · Issue #65127 · nodejs/node · GitHub
Open Graph Title: `stream.pipeline()` can both throw synchronously and invoke the callback reporting success · Issue #65127 · nodejs/node
X Title: `stream.pipeline()` can both throw synchronously and invoke the callback reporting success · Issue #65127 · nodejs/node
Description: Version v24.11.1, and main (aed4eaf89dd) Platform Reproduced on Windows 11 x64; the code path is platform independent. Subsystem stream What steps will reproduce the bug? When pipeline() throws synchronously while wiring the streams toge...
Open Graph Description: Version v24.11.1, and main (aed4eaf89dd) Platform Reproduced on Windows 11 x64; the code path is platform independent. Subsystem stream What steps will reproduce the bug? When pipeline() throws syn...
X Description: Version v24.11.1, and main (aed4eaf89dd) Platform Reproduced on Windows 11 x64; the code path is platform independent. Subsystem stream What steps will reproduce the bug? When pipeline() throws syn...
Opengraph URL: https://github.com/nodejs/node/issues/65127
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`stream.pipeline()` can both throw synchronously and invoke the callback reporting success","articleBody":"### Version\n\nv24.11.1, and `main` (`aed4eaf89dd`)\n\n### Platform\n\nReproduced on Windows 11 x64; the code path is platform independent.\n\n### Subsystem\n\nstream\n\n### What steps will reproduce the bug?\n\nWhen `pipeline()` throws synchronously while wiring the streams together, it can *also* invoke the callback, and the callback reports success. The caller therefore receives the same operation reported twice, once as an exception and once as a successful completion.\n\n```js\nimport { pipeline, Readable, Transform, PassThrough } from 'node:stream';\n\nfunction run(label, streams) {\n return new Promise((resolve) => {\n let threw = null;\n const calls = [];\n try {\n pipeline(...streams, (err) => calls.push(err ? err.code : 'NO ERROR'));\n } catch (err) {\n threw = err.code;\n }\n setTimeout(() => {\n console.log(`${label}`);\n console.log(` threw : ${threw}`);\n console.log(` callback invoked : ${calls.length} time(s) ${calls.length ? JSON.stringify(calls) : ''}`);\n resolve();\n }, 150);\n });\n}\n\n// A node stream in the middle wires pipe(), which increments finishCount\n// before the later stage throws.\nawait run('A. readable -> transform -> bad fn', [\n Readable.from(['a']),\n new Transform({ transform(c, e, cb) { cb(null, c); } }),\n () => 42,\n]);\n\n// Control: the throw happens before anything increments finishCount.\nawait run('B. readable -> bad fn -> passthrough (control)', [\n Readable.from(['a']),\n () => 42,\n new PassThrough(),\n]);\n```\n\n### How often does it reproduce? Is there a required condition?\n\nEvery time, for case A. The condition is that `finishCount` has already been incremented by an earlier stage before a later stage throws, which happens whenever a node stream is wired before the throwing stage.\n\n### What is the expected behavior? Why is that the expected behavior?\n\nA single failure should be reported once. If `pipeline()` throws synchronously then the callback should not also run, and it certainly should not run with no error, since the pipeline did not succeed.\n\nCase B shows the intended behaviour: the callback is not invoked when `pipeline()` throws.\n\n### What do you see instead?\n\n```\nnode v24.11.1\n\nA. readable -> transform -> bad fn\n threw : ERR_INVALID_RETURN_VALUE\n callback invoked : 1 time(s) [\"NO ERROR\"]\n\nB. readable -> bad fn -> passthrough (control)\n threw : ERR_INVALID_RETURN_VALUE\n callback invoked : 0 time(s)\n```\n\nIn case A the caller gets an `ERR_INVALID_RETURN_VALUE` exception and, shortly afterwards, a callback saying the pipeline finished with no error.\n\n### Additional information\n\nThe wiring loop in `pipelineImpl()` increments `finishCount` as it wires each stage, for example `finishCount += 2` before `pipe()` in the node stream branch. If a later stage throws, those already-wired stages remain live. When they subsequently close they call `finish()`, which decrements `finishCount`; on reaching zero `finishImpl()` runs with `final` true and schedules `process.nextTick(callback, error, value)`.\n\nBecause the streams were never destroyed by `pipeline()` on this path, `error` is still undefined at that point, so the callback reports success.\n\nIn case B the throw happens before any stage incremented `finishCount`, so nothing later reaches zero and the callback is correctly never scheduled. That difference is what makes the behaviour inconsistent rather than simply undesirable.\n\nThis was noticed while working on #65064, which touches the same synchronous-throw path but deliberately does not change this behaviour.\n","author":{"url":"https://github.com/shani-singh1","@type":"Person","name":"shani-singh1"},"datePublished":"2026-08-08T05:09:12Z","url":"https://github.com/nodejs/node/issues/65127"}
| 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:6e52e565-ba29-aa09-03c0-82b1b9b82075 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB12:ABE51:7EE39D:A5B28D:6AED35D1 |
| html-safe-nonce | 05cf04fc8a473ab2e58bff8c5785b2f8c7290e0fa430ce01e4a711d99bd733e4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjEyOkFCRTUxOjdFRTM5RDpBNUIyOEQ6NkFFRDM1RDEiLCJ2aXNpdG9yX2lkIjoiNzkxMjAzNDg3NDM5Njg0OTYxNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8639248b1e2df1f1efed980146a4ff9f33ff386ddda9bdaca280ea2d27dc733b |
| hovercard-subject-tag | issue:5095981501 |
| 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/65127/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1c580d4a751705d52995c0f6819dba26ddba8f45c416e35b8d631a372d3c02dc/nodejs/node/issues/65127 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1c580d4a751705d52995c0f6819dba26ddba8f45c416e35b8d631a372d3c02dc/nodejs/node/issues/65127 |
| og:image:alt | Version v24.11.1, and main (aed4eaf89dd) Platform Reproduced on Windows 11 x64; the code path is platform independent. Subsystem stream What steps will reproduce the bug? When pipeline() throws syn... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | shani-singh1 |
| 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