{"record":{"id":"398c1105725482fe","repo":"denoland/deno","slug":"could-not-open-nul-device-error","errorCode":null,"errorMessage":"Could not open NUL device (error {})","messagePattern":"Could not open NUL device \\(error (.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/util/windows.rs","lineNumber":250,"sourceCode":"          STD_INPUT_HANDLE => FILE_GENERIC_READ,\n          _ => FILE_GENERIC_WRITE | FILE_READ_ATTRIBUTES,\n        };\n        let security_attributes = SECURITY_ATTRIBUTES {\n          nLength: size_of::<SECURITY_ATTRIBUTES>() as u32,\n          lpSecurityDescriptor: std::ptr::null_mut(),\n          bInheritHandle: TRUE,\n        };\n        let file_handle = CreateFileA(\n          c\"\\\\\\\\?\\\\NUL\".as_ptr() as *const u8,\n          desired_access,\n          FILE_SHARE_READ | FILE_SHARE_WRITE,\n          &security_attributes,\n          OPEN_EXISTING,\n          FILE_ATTRIBUTE_NORMAL,\n          std::ptr::null_mut(),\n        );\n        if file_handle == INVALID_HANDLE_VALUE {\n          panic!(\"Could not open NUL device (error {})\", GetLastError());\n        }\n\n        // Assign the opened NUL handle to the missing stdio handle.\n        if SetStdHandle(std_handle, file_handle) == FALSE {\n          panic!(\"SetStdHandle failed (error {})\", GetLastError());\n        }\n      }\n    }\n  }\n}\n","sourceCodeStart":232,"sourceCodeEnd":261,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/util/windows.rs#L232-L261","documentation":"After detecting a missing stdio handle, Deno opens the \\\\?\\NUL device so the runtime always has three valid standard streams. If CreateFileA on NUL fails, startup cannot continue and Deno panics with the Win32 error. Opening the null device essentially never fails on a healthy system, so this points to environment-level breakage: handle exhaustion, object-namespace interference, or security software.","triggerScenarios":"Deno launched with a closed stdio slot while the NUL device open fails — desktop heap/handle exhaustion from a leaking process, restrictive AV/EDR blocking device opens, or a corrupted Windows install.","commonSituations":"Long-running machines with heavy handle leaks; locked-down corporate endpoints with aggressive EDR; Windows Server Core or sandboxed CI environments with restricted device access.","solutions":["Restart the machine (or the leaky parent process) to clear handle/desktop-heap exhaustion","Temporarily disable or add exclusions for AV/EDR to test interference","Give Deno explicit stdio redirection in the launch command so the NUL fallback is never needed","Capture the error code with `net helpmsg <code>` and report if reproducible on current Deno"],"exampleFix":":: before — inherited closed stdio slot forces the NUL fallback\ndeno run app.ts\n\n:: after — give every stream a real target\ndeno run app.ts < NUL > out.log 2>&1","handlingStrategy":"fallback","validationCode":":: pre-flight: give every stream a real target so the NUL fallback never runs\ndeno run app.ts < NUL > out.log 2>&1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Redirect stdio explicitly in service/scheduler contexts","Reboot or restart leaking processes when handle exhaustion is suspected","Add AV/EDR exclusions for the Deno binary when security software interferes"],"tags":["windows","stdio","nul-device","createfile","startup"],"backgroundTag":"win32-stdio-initialization-failed","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}