Title: Windows anonymous pipes do not work with createReadStream · Issue #57288 · nodejs/node · GitHub
Open Graph Title: Windows anonymous pipes do not work with createReadStream · Issue #57288 · nodejs/node
X Title: Windows anonymous pipes do not work with createReadStream · Issue #57288 · nodejs/node
Description: Version Tested with 22.14.0 and 20.18.1 Platform Microsoft Windows NT 10.0.22000.0 x64 Subsystem No response What steps will reproduce the bug? C# example for the anonymous pipe generator: using System; using System.Diagnostics; using Sy...
Open Graph Description: Version Tested with 22.14.0 and 20.18.1 Platform Microsoft Windows NT 10.0.22000.0 x64 Subsystem No response What steps will reproduce the bug? C# example for the anonymous pipe generator: using Sy...
X Description: Version Tested with 22.14.0 and 20.18.1 Platform Microsoft Windows NT 10.0.22000.0 x64 Subsystem No response What steps will reproduce the bug? C# example for the anonymous pipe generator: using Sy...
Opengraph URL: https://github.com/nodejs/node/issues/57288
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Windows anonymous pipes do not work with createReadStream","articleBody":"### Version\n\nTested with 22.14.0 and 20.18.1\n\n### Platform\n\n```text\nMicrosoft Windows NT 10.0.22000.0 x64\n```\n\n### Subsystem\n\n_No response_\n\n### What steps will reproduce the bug?\n\nC# example for the anonymous pipe generator:\n\n```csharp\nusing System;\nusing System.Diagnostics;\nusing System.IO;\nusing System.IO.Pipes;\nusing System.Threading.Tasks;\n\nnamespace DotNetSide\n{\n class Program\n {\n static async Task Main(string[] args)\n {\n using var pipeWriter = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable);\n using var pipeReader = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable);\n\n Process client = new Process();\n\n client.StartInfo.FileName = \"node\";\n client.StartInfo.Arguments = \"yourscript.js \" + pipeWriter.GetClientHandleAsString() + \" \" + pipeReader.GetClientHandleAsString();\n client.StartInfo.UseShellExecute = false;\n client.Start();\n\n pipeWriter.DisposeLocalCopyOfClientHandle();\n pipeReader.DisposeLocalCopyOfClientHandle();\n\n _ = StartReadingAsync(pipeReader);\n\n using var sw = new StreamWriter(pipeWriter)\n {\n AutoFlush = true\n };\n\n string message = Console.ReadLine();\n\n while (message != \"exit\")\n {\n await sw.WriteAsync(message);\n message = Console.ReadLine();\n }\n\n client.Close();\n }\n\n private static async Task StartReadingAsync(AnonymousPipeServerStream pipeReader)\n {\n try\n {\n StreamReader sr = new StreamReader(pipeReader);\n\n while (true)\n {\n var message = await sr.ReadLineAsync();\n\n if (message != null)\n {\n Console.WriteLine(message);\n }\n }\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n }\n }\n }\n}\n```\n\nJS code that should be able to read and write from the pipes' file descriptors:\n\n```js\nconst fs = require('fs');\nconst reader = fs.createReadStream(null, {fd: parseInt(process.argv[2], 10)});\nconst writer = fs.createWriteStream(null, {fd: parseInt(process.argv[3], 10)});\n\nreader.on('data', data => writer.write('echo: ' + data + '\\n'));\n\nsetInterval(()=> {}, 1000 * 60 * 60);\n```\n\n[Source](https://github.com/kblok/DotNetNodeInterprocessCommunication), should work according to the documentation and other examples I've seen.\n\n### How often does it reproduce? Is there a required condition?\n\nEverytime I try to open an inherited anonymous pipe with NodeJS\n\n### What is the expected behavior? Why is that the expected behavior?\n\n``'data'`` events should be emitted when read pipes have new data, and it should be possible to send data to write pipes too.\n\n### What do you see instead?\n\nWhenever I bind a callback to a ReadStream created from a pipe's FD:\n\n```\nnode:events:496\n throw er; // Unhandled 'error' event\n ^\n\nError: EBADF: bad file descriptor, close\nEmitted 'error' event on ReadStream instance at:\n at emitErrorNT (node:internal/streams/destroy:169:8)\n at emitErrorCloseNT (node:internal/streams/destroy:128:3)\n at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {\n errno: -4083,\n code: 'EBADF',\n syscall: 'close'\n}\n```\n\nWhenever I try to write to a WriteStream created from a pipe's FD:\n```\nnode:events:496\n throw er; // Unhandled 'error' event\n ^\n\nError: EBADF: bad file descriptor, close\nEmitted 'error' event on WriteStream instance at:\n at emitErrorNT (node:internal/streams/destroy:169:8)\n at emitErrorCloseNT (node:internal/streams/destroy:128:3)\n at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {\n errno: -4083,\n code: 'EBADF',\n syscall: 'close'\n}\n```\n\n### Additional information\n\nThe same Anonymous pipe generator C# program given as an example works well with C++ using the Windows API, so it's not a C# problem:\n```cpp\n#include \u003ciostream>\n#include \u003cstring>\n#include \u003cwindows.h>\n#include \u003carray>\n\nint main(int argc, const char** argv)\n{\n std::string pipeHandleString = argv[1];\n int pipeHandleInt = std::stoi(pipeHandleString);\n\n HANDLE pipeHandle = (void*)pipeHandleInt;\n\n std::array\u003cchar, 256> buffer = {};\n\n DWORD numberOfBytesRead;\n\n BOOL result = false;\n\n while (result = ReadFile(pipeHandle, &buffer, 256, &numberOfBytesRead, nullptr)) {\n buffer[numberOfBytesRead] = '\\0';\n std::cout \u003c\u003c \"echo: \" \u003c\u003c buffer.data() \u003c\u003c std::endl;\n }\n}\n```\n\nOf course, it also works with C# clients.","author":{"url":"https://github.com/mgirolet-gl","@type":"Person","name":"mgirolet-gl"},"datePublished":"2025-03-03T12:23:25Z","url":"https://github.com/nodejs/node/issues/57288"}
| 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:04c6a9e1-da9e-bf0e-ef10-7862efc96031 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CD16:3075D4:48BE75:5E82EB:6AED245E |
| html-safe-nonce | 36b4f4242eeac94c9adcba9aeb2acd757942b58309ae9fc1632b842779eac832 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRDE2OjMwNzVENDo0OEJFNzU6NUU4MkVCOjZBRUQyNDVFIiwidmlzaXRvcl9pZCI6Ijc4NTE3MzE0NTA1MDE4NjY1OTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 05823326b4de9c7f436d3f54a680af05c3bf16192f1a95aae96bd7df1ead4918 |
| hovercard-subject-tag | issue:2891101793 |
| 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/57288/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4fd31538003f9cf2fa550ddc029376eafafbb6471b330312ef8e21ec585ce76c/nodejs/node/issues/57288 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4fd31538003f9cf2fa550ddc029376eafafbb6471b330312ef8e21ec585ce76c/nodejs/node/issues/57288 |
| og:image:alt | Version Tested with 22.14.0 and 20.18.1 Platform Microsoft Windows NT 10.0.22000.0 x64 Subsystem No response What steps will reproduce the bug? C# example for the anonymous pipe generator: using Sy... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mgirolet-gl |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9d95365dda0576efe9b71f45807595e396bd0ca9286fba5367a05048e6ddf8f2 |
| 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 | 98b41fa4b5635ceb45a4c54320fced73817ff290 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width