{"record":{"id":"69de16c030afc5f4","repo":"denoland/deno","slug":"failed-to-start-winsocket","errorCode":null,"errorMessage":"Failed to start winsocket","messagePattern":"Failed to start winsocket","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ext/os/sys_info.rs","lineNumber":175,"sourceCode":"  {\n    use std::ffi::OsString;\n    use std::mem;\n    use std::os::windows::ffi::OsStringExt;\n\n    use windows_sys::Win32::Networking::WinSock::GetHostNameW;\n    use windows_sys::Win32::Networking::WinSock::WSAStartup;\n\n    let namelen = 256;\n    let mut name: Vec<u16> = vec![0u16; namelen];\n    // Start winsock to make `GetHostNameW` work correctly\n    // https://github.com/retep998/winapi-rs/issues/296\n    // SAFETY: Win32 call\n    WINSOCKET_INIT.call_once(|| unsafe {\n      let mut data = mem::zeroed();\n      // MAKEWORD(2, 2)\n      let wsa_startup_result = WSAStartup(0x0202, &mut data);\n      if wsa_startup_result != 0 {\n        panic!(\"Failed to start winsocket\");\n      }\n    });\n    let err =\n      // SAFETY: length of wide string is 256 chars or less.\n      // https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-gethostnamew\n      unsafe { GetHostNameW(name.as_mut_ptr(), namelen as libc::c_int) };\n\n    if err == 0 {\n      // TODO(@littledivy): Probably not the most efficient way.\n      let len = name.iter().take_while(|&&c| c != 0).count();\n      OsString::from_wide(&name[..len])\n        .to_string_lossy()\n        .into_owned()\n    } else {\n      String::from(\"\")\n    }\n  }\n}","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/os/sys_info.rs#L157-L193","documentation":"On Windows, os.hostname() resolves through GetHostNameW, which requires Winsock to be initialized; Deno calls WSAStartup(2.2) once per process and panics if it returns a nonzero error. A failing WSAStartup means the Winsock subsystem itself is unusable — catalog corruption or critical resource exhaustion — not a network outage or DNS problem.","triggerScenarios":"Calling os.hostname() (node:os) on a Windows host where WSAStartup fails: winsock catalog corruption after installing VPN/LSP software, severely resource-exhausted machines, or locked-down minimal Windows environments.","commonSituations":"After installing/uninstalling VPNs, proxies, or firewall software that corrupts the winsock catalog; minimal Windows containers; endpoints with aggressive security tooling that blocks Winsock initialization.","solutions":["Run `netsh winsock reset` as administrator and reboot — the canonical fix for catalog corruption","Verify in a plain console first; if only a sandboxed environment fails, adjust that environment","As a stopgap, read the hostname from the COMPUTERNAME environment variable instead of os.hostname()","Update Deno and report if WSAStartup still fails on a healthy machine"],"exampleFix":"// before — panics when winsock is broken\nconst host = os.hostname();\n\n// after — environment first, winsock-backed call only as fallback\nconst host = Deno.env.get(\"COMPUTERNAME\") ?? os.hostname();","handlingStrategy":"fallback","validationCode":"function hostnameSafe(): string {\n  const env = Deno.env.get(\"COMPUTERNAME\") ?? Deno.env.get(\"HOSTNAME\");\n  if (env) return env;\n  return os.hostname(); // last resort: touches winsock\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["On Windows, prefer the COMPUTERNAME env var in code that must survive broken winsock","Run `netsh winsock reset` after installing VPN/proxy/LSP software that may corrupt the catalog","Avoid os.hostname() in minimal Windows containers where winsock may be unavailable"],"tags":["windows","os","hostname","winsock","wsastartup"],"backgroundTag":"wsastartup-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"}