ansible/ansible · error · Win32Exception

STDIN pipe handle setup failed

Error message

STDIN pipe handle setup failed

What it means

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.

Source

Thrown at lib/ansible/module_utils/csharp/Ansible.Process.cs:375

            out SafeFileHandle stdinRead, out SafeFileHandle stdinWrite)
        {
            NativeHelpers.SECURITY_ATTRIBUTES pipesec = new NativeHelpers.SECURITY_ATTRIBUTES();
            pipesec.bInheritHandle = true;

            if (!NativeMethods.CreatePipe(out stdoutRead, out stdoutWrite, pipesec, 0))
                throw new Win32Exception("STDOUT pipe setup failed");
            if (!NativeMethods.SetHandleInformation(stdoutRead, NativeHelpers.HandleFlags.INHERIT, 0))
                throw new Win32Exception("STDOUT pipe handle setup failed");

            if (!NativeMethods.CreatePipe(out stderrRead, out stderrWrite, pipesec, 0))
                throw new Win32Exception("STDERR pipe setup failed");
            if (!NativeMethods.SetHandleInformation(stderrRead, NativeHelpers.HandleFlags.INHERIT, 0))
                throw new Win32Exception("STDERR pipe handle setup failed");

            if (!NativeMethods.CreatePipe(out stdinRead, out stdinWrite, pipesec, 0))
                throw new Win32Exception("STDIN pipe setup failed");
            if (!NativeMethods.SetHandleInformation(stdinWrite, NativeHelpers.HandleFlags.INHERIT, 0))
                throw new Win32Exception("STDIN pipe handle setup failed");

            si.startupInfo.hStdOutput = stdoutWrite;
            si.startupInfo.hStdError = stderrWrite;
            si.startupInfo.hStdInput = stdinRead;
        }

        internal static SafeMemoryBuffer CreateEnvironmentPointer(IDictionary environment)
        {
            IntPtr lpEnvironment = IntPtr.Zero;
            if (environment != null && environment.Count > 0)
            {
                StringBuilder environmentString = new StringBuilder();
                foreach (DictionaryEntry kv in environment)
                    environmentString.AppendFormat("{0}={1}\0", kv.Key, kv.Value);
                environmentString.Append('\0');

                lpEnvironment = Marshal.StringToHGlobalUni(environmentString.ToString());
            }

View on GitHub (pinned to 9cf16a4aca)

Solutions

  1. Use the Win32ErrorCode to distinguish invalid-handle from resource failure.
  2. Eliminate handle leaks in surrounding code.
  3. Reduce concurrent process creation on the node.
  4. Escalate upstream with error code and reproduction if the host is healthy.
Defensive patterns

Strategy: try-catch

Try / catch

try
{
    result = Process.CreateProcess(app, cmd, cwd, env);
}
catch (Win32Exception ex) when (ex.Message.Contains("STDIN pipe handle setup"))
{
    // final pipe step failed; same remediation as 50-54: release handles, reduce concurrency, retry
}

Prevention

When it happens

Trigger: Invalid stdinWrite handle at the final setup step; handle exhaustion reached after three pipe pairs; restricted SetHandleInformation by policy software.

Common situations: Resource exhaustion scenarios alongside 50-54; essentially an internal invariant; not playbook-fixable.

Related errors


AI-assisted analysis of ansible/ansible@9cf16a4aca (2026-08-15). Data as JSON: /api/errors/d47673b59cab2301. Report an issue: GitHub.