{"record":{"id":"bbce27c927734bdf","repo":"felixse/FluentTerminal","slug":"failed-to-create-pipe","errorCode":null,"errorMessage":"failed to create pipe","messagePattern":"failed to create pipe","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"critical","filePath":"FluentTerminal.SystemTray/Services/ConPty/PseudoConsolePipe.cs","lineNumber":25,"sourceCode":"namespace FluentTerminal.SystemTray.Services.ConPty\n{\n    /// <summary>\n    /// A pipe used to talk to the pseudoconsole, as described in:\n    /// https://docs.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session\n    /// </summary>\n    /// <remarks>\n    /// We'll have two instances of this class, one for input and one for output.\n    /// </remarks>\n    internal sealed class PseudoConsolePipe : IDisposable\n    {\n        public readonly SafeFileHandle ReadSide;\n        public readonly SafeFileHandle WriteSide;\n\n        public PseudoConsolePipe()\n        {\n            if (!CreatePipe(out ReadSide, out WriteSide, IntPtr.Zero, 0))\n            {\n                throw new Win32Exception(Marshal.GetLastWin32Error(), \"failed to create pipe\");\n            }\n        }\n\n        ~PseudoConsolePipe()\n        {\n            Dispose(false);\n        }\n\n        #region IDisposable\n\n        public void Dispose()\n        {\n            Dispose(true);\n            GC.SuppressFinalize(this);\n        }\n\n        void Dispose(bool disposing)\n        {","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/felixse/FluentTerminal/blob/ba83ec485eea8d8ee65825711731300bee2e76ed/FluentTerminal.SystemTray/Services/ConPty/PseudoConsolePipe.cs#L7-L43","documentation":"Thrown by PseudoConsolePipe's constructor when the Win32 CreatePipe P/Invoke returns false. The ConPty backend creates an anonymous pipe (one read handle, one write handle) to feed input to and drain output from the pseudoconsole; if the kernel cannot create the pipe, GetLastWin32Error is wrapped in a Win32Exception with this message.","triggerScenarios":"Constructing a PseudoConsolePipe (two are made per Terminal.Start: input and output) on a system where CreatePipe fails - typically due to handle exhaustion or resource limits, not normal usage.","commonSituations":"Process has leaked handles and hit the 10k-default handle quota; running under a heavily constrained session/job object; rare kernel/resource pressure. ConPty itself requires Windows 10 1809+.","solutions":["Ensure the app disposes Terminal/PseudoConsolePipe instances promptly to avoid handle leaks.","Run on Windows 10 1809 (build 17763) or later where the ConPty API is available.","Inspect the Win32Exception.NativeErrorCode (e.g. ERROR_TOO_MANY_OPEN_FILES) to pinpoint resource exhaustion.","Restart the app/session to release leaked handles."],"exampleFix":"// before\nif (!CreatePipe(out ReadSide, out WriteSide, IntPtr.Zero, 0))\n    throw new Win32Exception(Marshal.GetLastWin32Error(), \"failed to create pipe\");\n\n// after - include the native error code in the message for diagnostics\nint err = Marshal.GetLastWin32Error();\nthrow new Win32Exception(err, $\"failed to create pipe (Win32 error {err})\");","handlingStrategy":"try-catch","validationCode":"// No cheap pre-check; ensure handles are disposed to avoid exhaustion.\n// Monitor handle count before creating a terminal:\nusing (var proc = Process.GetCurrentProcess())\n    if (proc.HandleCount > 9000) logger.Warn(\"Handle count high; ConPty pipe creation may fail.\");","typeGuard":null,"tryCatchPattern":"try { terminal = new Terminal(); /* pipes created in Start */ }\ncatch (System.ComponentModel.Win32Exception ex) { logger.Error(ex, $\"pipe create failed (Win32 {ex.NativeErrorCode})\"); fallbackToWinPty(); }","preventionTips":["Dispose Terminal/PseudoConsolePipe promptly to prevent handle leaks.","Run on Windows 10 1809+ for ConPty support.","Inspect NativeErrorCode to diagnose resource exhaustion.","Restart the app if handle counts climb."],"tags":["conpty","win32","pipe","native","terminal-backend"],"backgroundTag":null,"analyzedSha":"ba83ec485eea8d8ee65825711731300bee2e76ed","analyzedAt":"2026-08-13T21:23:15.467Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}