languagetool-org/languagetool · critical · IOException
No free port in range ( - ) found.
Error message
No free port in range ( - ) found.
What it means
HTTPServer.getPortFromRange scans the configured minPort-maxPort range trying to open each port; if none can be bound it throws this IOException. It means every port in the range was already taken (or blocked) when the server started. The server cannot serve HTTP without a listening socket, so startup aborts.
Source
Thrown at languagetool-server/src/main/java/org/languagetool/server/HTTPServer.java:147
}
}
private int getPortFromRange(int minPort, int maxPort) throws IOException {
if (minPort > 0 && minPort < maxPort) {
log.info("Try to find a free Port for Server in range {}-{}", minPort, maxPort);
for (int p = minPort; p <= maxPort; p++) {
try {
log.info("Check port {}", p);
ServerSocket serverSocket = new ServerSocket(p);
port = serverSocket.getLocalPort();
serverSocket.close();
log.info("Port {} is available.", p);
return p;
} catch (IOException ex) {
log.debug("Port {} is not available.", p);
}
}
throw new IOException("No free port in range ("+ minPort + " - " + maxPort + ") found.");
} else {
throw new IOException("Invalid port configuration found. " +
"The value for '--port' need to be greater than 0 or if set to 0 you need to specify a minPort and maxPort in your properties file (minPort must be lower that maxPort).");
}
}
@Override
public void stop() {
super.stop();
if (executorService != null) {
executorService.shutdownNow();
}
}
public static void main(String[] args) {
if (usageRequested(args)) {
System.out.println("Usage: " + HTTPServer.class.getSimpleName() + " [--config propertyFile] [--port|-p port] [--public]");
System.out.println(" --config FILE a Java property file (one key=value entry per line) with values for:");View on GitHub (pinned to 2e990059ce)
Solutions
- Check which process occupies the range (ss -ltnp or netstat -ano) and stop the conflicting process
- Widen the minPort/maxPort range in the server properties file or pick an unoccupied range
- Use a fixed free port by setting --port to a specific available value instead of port 0 with a range
- Verify no firewall/SELinux/container policy prevents binding to that range
Example fix
# before (server.properties) minPort=8081 maxPort=8081 # after minPort=8081 maxPort=8090
Defensive patterns
Strategy: validation
Validate before calling
// before starting with port 0 + range
int free = -1;
for (int p = minPort; p <= maxPort; p++) {
try (java.net.ServerSocket s = new java.net.ServerSocket(p)) { free = p; break; }
catch (java.io.IOException ignored) {}
}
if (free == -1) throw new IllegalStateException("No free port in " + minPort + "-" + maxPort); Try / catch
try { server.start(); } catch (IOException e) {
if (e.getMessage().contains("No free port")) { widenRangeOrPickStaticPort(); } else throw e;
} Prevention
- Reserve distinct, wide port ranges per service instance
- Check listening ports with ss/netstat before deployment
- Health-check that the server actually bound the expected port
When it happens
Trigger: Starting the server with --port 0 (or port=0 in the properties file) plus minPort/maxPort properties set, while all ports in [minPort, maxPort] are already bound by other processes or unreachable due to OS restrictions.
Common situations: Running multiple LanguageTool instances on the same machine with overlapping port ranges; a stale process still holding the ports; running in a container/pod whose network policy blocks binding to that range; minPort==maxPort that is occupied.
Related errors
- Could not connect to server at ${serverBaseUrl}
- https_server_start_failed
- http_server_start_failed
- Invalid port configuration found. The value for '--port' nee
- Could not start LanguageTool HTTP server on , port
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/084d5221b49625e5.
Report an issue: GitHub.