{"record":{"id":"d47673b59cab2301","repo":"ansible/ansible","slug":"stdin-pipe-handle-setup-failed","errorCode":null,"errorMessage":"STDIN pipe handle setup failed","messagePattern":"STDIN pipe handle setup failed","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"error","filePath":"lib/ansible/module_utils/csharp/Ansible.Process.cs","lineNumber":375,"sourceCode":"            out SafeFileHandle stdinRead, out SafeFileHandle stdinWrite)\n        {\n            NativeHelpers.SECURITY_ATTRIBUTES pipesec = new NativeHelpers.SECURITY_ATTRIBUTES();\n            pipesec.bInheritHandle = true;\n\n            if (!NativeMethods.CreatePipe(out stdoutRead, out stdoutWrite, pipesec, 0))\n                throw new Win32Exception(\"STDOUT pipe setup failed\");\n            if (!NativeMethods.SetHandleInformation(stdoutRead, NativeHelpers.HandleFlags.INHERIT, 0))\n                throw new Win32Exception(\"STDOUT pipe handle setup failed\");\n\n            if (!NativeMethods.CreatePipe(out stderrRead, out stderrWrite, pipesec, 0))\n                throw new Win32Exception(\"STDERR pipe setup failed\");\n            if (!NativeMethods.SetHandleInformation(stderrRead, NativeHelpers.HandleFlags.INHERIT, 0))\n                throw new Win32Exception(\"STDERR pipe handle setup failed\");\n\n            if (!NativeMethods.CreatePipe(out stdinRead, out stdinWrite, pipesec, 0))\n                throw new Win32Exception(\"STDIN pipe setup failed\");\n            if (!NativeMethods.SetHandleInformation(stdinWrite, NativeHelpers.HandleFlags.INHERIT, 0))\n                throw new Win32Exception(\"STDIN pipe handle setup failed\");\n\n            si.startupInfo.hStdOutput = stdoutWrite;\n            si.startupInfo.hStdError = stderrWrite;\n            si.startupInfo.hStdInput = stdinRead;\n        }\n\n        internal static SafeMemoryBuffer CreateEnvironmentPointer(IDictionary environment)\n        {\n            IntPtr lpEnvironment = IntPtr.Zero;\n            if (environment != null && environment.Count > 0)\n            {\n                StringBuilder environmentString = new StringBuilder();\n                foreach (DictionaryEntry kv in environment)\n                    environmentString.AppendFormat(\"{0}={1}\\0\", kv.Key, kv.Value);\n                environmentString.Append('\\0');\n\n                lpEnvironment = Marshal.StringToHGlobalUni(environmentString.ToString());\n            }","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/ansible/ansible/blob/9cf16a4aca7898481c257f1e17ad28d0b67b1f85/lib/ansible/module_utils/csharp/Ansible.Process.cs#L357-L393","documentation":"Thrown when SetHandleInformation fails clearing INHERIT on the STDIN write handle (parent side), the last pipe-setup step in Process.CreateStdioPipes. The pattern matches errors 51/53: only the child's ends stay inheritable, and failure to mark the parent's write end non-inheritable aborts setup.","triggerScenarios":"Invalid stdinWrite handle at the final setup step; handle exhaustion reached after three pipe pairs; restricted SetHandleInformation by policy software.","commonSituations":"Resource exhaustion scenarios alongside 50-54; essentially an internal invariant; not playbook-fixable.","solutions":["Use the Win32ErrorCode to distinguish invalid-handle from resource failure.","Eliminate handle leaks in surrounding code.","Reduce concurrent process creation on the node.","Escalate upstream with error code and reproduction if the host is healthy."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    result = Process.CreateProcess(app, cmd, cwd, env);\n}\ncatch (Win32Exception ex) when (ex.Message.Contains(\"STDIN pipe handle setup\"))\n{\n    // final pipe step failed; same remediation as 50-54: release handles, reduce concurrency, retry\n}","preventionTips":["Centralize child-process creation in one helper that owns handle lifetimes end to end.","Add handle-count assertions/logging in long-running module code.","Escalate to host-level investigation if errors 50-55 recur on an otherwise idle node."],"tags":["windows","pipe","win32","handle","resources"],"backgroundTag":null,"analyzedSha":"9cf16a4aca7898481c257f1e17ad28d0b67b1f85","analyzedAt":"2026-08-15T00:15:47.100Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}