netchx/netch · error · MessageException
The {0} port is in use.
Error message
The {0} port is in use. What it means
Thrown by MainController.PortCheck when PortHelper.CheckPort raises PortInUseException — an active TCP or UDP listener already exists on the requested port (checked via IPGlobalProperties.GetActiveTcpListeners/GetActiveUdpListeners). The formatted message includes the human-readable portName and the port number.
Source
Thrown at Netch/Controllers/MainController.cs:142
}
catch (Exception e)
{
Log.Error(e, "MainController Stop Error");
}
ServerController = null;
ModeController = null;
}
public static void PortCheck(ushort port, string portName, PortType portType = PortType.Both)
{
try
{
PortHelper.CheckPort(port, portType);
}
catch (PortInUseException)
{
throw new MessageException(i18N.TranslateFormat("The {0} port is in use.", $"{portName} ({port})"));
}
catch (PortReservedException)
{
throw new MessageException(i18N.TranslateFormat("The {0} port is reserved by system.", $"{portName} ({port})"));
}
}
public static void TryReleaseTcpPort(ushort port, string portName)
{
foreach (var p in PortHelper.GetProcessByUsedTcpPort(port))
{
var fileName = p.MainModule?.FileName;
if (fileName == null)
continue;
if (fileName.StartsWith(Global.NetchDir))
{
p.Kill();View on GitHub (pinned to 9d99eb1c5a)
Solutions
- Identify the holder: `netstat -ano | findstr :<port>` then tasklist / find the PID.
- Stop the conflicting application or pick a different port in Settings.
- Use MainController.TryReleaseTcpPort if the holder is another Netch process (it auto-kills Netch-owned processes).
- Restart Netch cleanly so stale listeners are released.
Defensive patterns
Strategy: validation
Validate before calling
MainController.PortCheck(port, portName, PortType.Both);
// throws MessageException("The {portName} (port) port is in use.") if a listener exists Try / catch
try { MainController.PortCheck(port, portName); }
catch (MessageException ex) when (ex.Message.Contains("port is in use"))
{
// prompt the user to change the port or stop the conflicting app
SuggestAlternatePort(port);
} Prevention
- Call MainController.PortCheck during settings save, not only at Start, to surface conflicts early.
- Default Netch to low, rarely-used ports (1080, 1086) to avoid common conflicts.
- Use TryReleaseTcpPort when the holder might be another Netch process.
- Teach users to check `netstat -ano | findstr :<port>`.
When it happens
Trigger: Another application (or a previous, not-fully-stopped Netch process) is bound to the Socks5 local port, the mode controller's port, or the AioDNS port; calling PortCheck for a port a non-Netch app holds.
Common situations: Netch crashed without releasing its Socks5 port and is restarted; another proxy client (Clash, v2rayN) uses the same port; a development server occupies the port.
Related errors
- The {0} port is reserved by system.
- The {0} port is used by {1}.
- DNS format invalid
- Lookup Server hostname failed
- Invalid tcp type {server.FakeType}
AI-assisted analysis of netchx/netch@9d99eb1c5a (2026-08-13).
Data as JSON: /api/errors/2898484cdc56538e.
Report an issue: GitHub.