denoland/deno · error
SetStdHandle failed (error {})
Error message
SetStdHandle failed (error {}) What it means
The final step of Deno's Windows stdio repair: after successfully opening \\?\NUL, it calls SetStdHandle to install that handle as the missing standard stream. If the assignment fails, the process would run with inconsistent stdio, so Deno panics with the last Win32 error. Like the other stdio-repair panics, it reflects a broken process environment rather than anything in user code.
Source
Thrown at cli/util/windows.rs:255
lpSecurityDescriptor: std::ptr::null_mut(),
bInheritHandle: TRUE,
};
let file_handle = CreateFileA(
c"\\\\?\\NUL".as_ptr() as *const u8,
desired_access,
FILE_SHARE_READ | FILE_SHARE_WRITE,
&security_attributes,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
std::ptr::null_mut(),
);
if file_handle == INVALID_HANDLE_VALUE {
panic!("Could not open NUL device (error {})", GetLastError());
}
// Assign the opened NUL handle to the missing stdio handle.
if SetStdHandle(std_handle, file_handle) == FALSE {
panic!("SetStdHandle failed (error {})", GetLastError());
}
}
}
}
}
View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Redirect stdio explicitly in the launching command so the repair path is never attempted
- Reboot to reset kernel handle state
- Test outside the sandbox/EDR layer; add exclusions if that resolves it
- Report with the error code if reproducible on the latest Deno
Example fix
:: before — rely on deno repairing a closed stdio slot deno run app.ts :: after — explicit redirection avoids the repair entirely deno run app.ts < NUL > out.log 2>&1
Defensive patterns
Strategy: fallback
Prevention
- Explicit stdio redirection avoids the entire stdio-repair path
- Test the same command outside sandboxes/job objects to identify restricted-handle environments
- Report persistent SetStdHandle failures with the decoded error code
When it happens
Trigger: Same precondition as the NUL-open failure (a closed stdio slot) plus a SetStdHandle failure — handle table corruption, security software intercepting handle mutation, or unusual container/sandbox layers restricting handle operations on Windows.
Common situations: Deno spawned inside sandboxed CI runners or job objects that restrict handle mutation; rare enough that a reboot or a different launch method (explicit redirection) usually clears it.
Related errors
- GetHandleInformation failed (error {})
- Could not open NUL device (error {})
- Invalid handle
- Invalid stdio count
- Cannot serve HTTP requests: either a `handler` or `options`
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/d2dcf7df207f250f.
Report an issue: GitHub.