{"record":{"id":"08d19c98a8aacf20","repo":"netchx/netch","slug":"the-0-port-is-reserved-by-system","errorCode":null,"errorMessage":"The {0} port is reserved by system.","messagePattern":"The (.+?) port is reserved by system\\.","errorType":"exception","errorClass":"MessageException","httpStatus":null,"severity":"error","filePath":"Netch/Controllers/MainController.cs","lineNumber":146,"sourceCode":"        }\n\n        ServerController = null;\n        ModeController = null;\n    }\n\n    public static void PortCheck(ushort port, string portName, PortType portType = PortType.Both)\n    {\n        try\n        {\n            PortHelper.CheckPort(port, portType);\n        }\n        catch (PortInUseException)\n        {\n            throw new MessageException(i18N.TranslateFormat(\"The {0} port is in use.\", $\"{portName} ({port})\"));\n        }\n        catch (PortReservedException)\n        {\n            throw new MessageException(i18N.TranslateFormat(\"The {0} port is reserved by system.\", $\"{portName} ({port})\"));\n        }\n    }\n\n    public static void TryReleaseTcpPort(ushort port, string portName)\n    {\n        foreach (var p in PortHelper.GetProcessByUsedTcpPort(port))\n        {\n            var fileName = p.MainModule?.FileName;\n            if (fileName == null)\n                continue;\n\n            if (fileName.StartsWith(Global.NetchDir))\n            {\n                p.Kill();\n                p.WaitForExit();\n            }\n            else\n            {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/netchx/netch/blob/9d99eb1c5a2acbf2a34f2600f94242601019a300/Netch/Controllers/MainController.cs#L128-L164","documentation":"Thrown by MainController.PortCheck when PortHelper.CheckPort raises PortReservedException — the port falls inside a Windows excluded port range parsed from `netsh int ipv4 show excludedportrange`. These ranges are reserved (typically by Hyper-V/WSL/Docker/Windows update) and cannot be bound even when no listener is active.","triggerScenarios":"Configured Socks5/mode/AioDNS port lies within a TCP or UDP excluded range populated by Hyper-V dynamic port reservations; the reserved-range list changed after a reboot or after starting Docker/WSL.","commonSituations":"Hyper-V/WSL2 installed, which reserves large swaths of dynamic ports; Docker Desktop reserving ports; user picked a port in the 50000+ dynamic range that Windows handed to Hyper-V.","solutions":["List reserved ranges: `netsh int ipv4 show excludedportrange protocol=tcp` (and udp).","Change the configured port to one outside every listed range (low ports like 1080/1086 usually safe).","Optionally shrink Hyper-V's dynamic range: `netsh int ipv4 set dynamicport tcp start=49152 num=16384` after restarting Hyper-V compute service.","Reboot after changing reservations so the excluded list refreshes."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Reject ports inside Windows excluded ranges before binding.\n// PortHelper.CheckPort already throws PortReservedException; call it on the settings page:\ntry { PortHelper.CheckPort(port, PortType.Both); }\ncatch (PortReservedException) { /* mark port invalid in the UI */ }","typeGuard":null,"tryCatchPattern":"try { MainController.PortCheck(port, portName); }\ncatch (MessageException ex) when (ex.Message.Contains(\"reserved by system\"))\n{\n    SuggestPortsOutsideExcludedRanges(portName);\n}","preventionTips":["Pick ports below the Windows dynamic range (e.g. 1080) to dodge Hyper-V/WSL reservations.","Cache the `netsh int ipv4 show excludedportrange` list at startup and reject reserved ports in the UI.","After installing Hyper-V/Docker/WSL, re-check your chosen port.","Reboot after changing dynamic port ranges so the excluded list refreshes."],"tags":["port","windows","config","validation"],"backgroundTag":null,"analyzedSha":"9d99eb1c5a2acbf2a34f2600f94242601019a300","analyzedAt":"2026-08-13T14:12:19.105Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}