{"record":{"id":"4cdd6af3e85f2871","repo":"jesseduffield/lazygit","slug":"createpipe-in-w","errorCode":null,"errorMessage":"CreatePipe (in): %w","messagePattern":"CreatePipe \\(in\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/oscommands/pty_windows.go","lineNumber":281,"sourceCode":"\t\t}\n\t}\n\tif len(found) != 1 {\n\t\treturn 0\n\t}\n\th, err := windows.OpenProcess(windows.SYNCHRONIZE|windows.PROCESS_TERMINATE, false, found[0])\n\tif err != nil {\n\t\treturn 0\n\t}\n\treturn h\n}\n\nfunc StartPty(cmd *exec.Cmd, cols, rows uint16) (sp StartedPty, err error) {\n\t// Two pipes: one for the child's stdin (we never write to it, but ConPTY\n\t// needs a handle), one for the child's stdout/stderr multiplexed through\n\t// the pseudoconsole.\n\tvar inRead, inWrite, outRead, outWrite windows.Handle\n\tif err = windows.CreatePipe(&inRead, &inWrite, nil, 0); err != nil {\n\t\treturn StartedPty{}, fmt.Errorf(\"CreatePipe (in): %w\", err)\n\t}\n\tdefer func() {\n\t\tif err != nil {\n\t\t\t_ = windows.CloseHandle(inWrite)\n\t\t}\n\t}()\n\tif err = windows.CreatePipe(&outRead, &outWrite, nil, 0); err != nil {\n\t\t_ = windows.CloseHandle(inRead)\n\t\treturn StartedPty{}, fmt.Errorf(\"CreatePipe (out): %w\", err)\n\t}\n\tdefer func() {\n\t\tif err != nil {\n\t\t\t_ = windows.CloseHandle(outRead)\n\t\t}\n\t}()\n\n\t// CreatePseudoConsole dupes the handles it needs internally; we release\n\t// our references to the child-side ends immediately after.","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/commands/oscommands/pty_windows.go#L263-L299","documentation":"StartPty on Windows first creates the child-stdin pipe via CreatePipe. If the syscall fails, this wrapped error is returned; the deferred cleanup only closes handles that were successfully created, so a failure here leaks nothing. It almost always reflects resource exhaustion rather than API misuse.","triggerScenarios":"windows.CreatePipe returning an error: handle/memory exhaustion (no free handles), restrictive job limits on the lazygit process, or kernel resource pressure while spawning many interactive commands.","commonSituations":"Running many PTY-backed commands (interactive shells in lazygit) concurrently for long sessions; sandboxed/CI environments capping handle counts; heavy system load.","solutions":["Close other running interactive commands/processes and retry to free handles.","Restart lazygit if the session accumulated leaked handles (e.g. after crashes of spawned commands).","If persistent, check the machine's handle limits / antivirus interference with pipe creation.","As a workaround, use lazygit's non-PTY command running where the feature allows."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"sp, err := oscommands.StartPty(cmd, cols, rows)\nif err != nil {\n    if strings.Contains(err.Error(), \"CreatePipe\") {\n        // resource exhaustion: degrade to plain pipes instead of a PTY\n        return cmd.StdoutPipe()\n    }\n    return err\n}","preventionTips":["Bound the number of simultaneously running PTY commands in your app.","Reap/close finished PTYs promptly; a per-session restart valve limits leak damage.","Log the wrapped syscall error to distinguish handle exhaustion from policy failures."],"tags":["windows","pty","conpty","syscall","pipes"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}