{"record":{"id":"084d5221b49625e5","repo":"languagetool-org/languagetool","slug":"no-free-port-in-range-found","errorCode":null,"errorMessage":"No free port in range ( - ) found.","messagePattern":"No free port in range \\( - \\) found\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"languagetool-server/src/main/java/org/languagetool/server/HTTPServer.java","lineNumber":147,"sourceCode":"    }\n  }\n  \n  private int getPortFromRange(int minPort, int maxPort) throws IOException {\n    if (minPort > 0 && minPort < maxPort) {\n         log.info(\"Try to find a free Port for Server in range {}-{}\", minPort, maxPort);\n         for (int p = minPort; p <= maxPort; p++) {\n           try {\n             log.info(\"Check port {}\", p);\n             ServerSocket serverSocket = new ServerSocket(p);\n             port = serverSocket.getLocalPort();\n             serverSocket.close();\n             log.info(\"Port {} is available.\", p);\n             return p;\n           } catch (IOException ex) {\n             log.debug(\"Port {} is not available.\", p);\n           }\n         }\n         throw new IOException(\"No free port in range (\"+ minPort + \" - \" + maxPort + \") found.\");\n    } else {\n      throw new IOException(\"Invalid port configuration found. \" +\n                            \"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).\");\n    }\n  }\n\n  @Override\n  public void stop() {\n    super.stop();\n    if (executorService != null) {\n      executorService.shutdownNow();\n    }\n  }\n\n  public static void main(String[] args) {\n    if (usageRequested(args)) {\n      System.out.println(\"Usage: \" + HTTPServer.class.getSimpleName() + \" [--config propertyFile] [--port|-p port] [--public]\");\n      System.out.println(\"  --config FILE  a Java property file (one key=value entry per line) with values for:\");","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-server/src/main/java/org/languagetool/server/HTTPServer.java#L129-L165","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before (server.properties)\nminPort=8081\nmaxPort=8081\n# after\nminPort=8081\nmaxPort=8090","handlingStrategy":"validation","validationCode":"// before starting with port 0 + range\nint free = -1;\nfor (int p = minPort; p <= maxPort; p++) {\n  try (java.net.ServerSocket s = new java.net.ServerSocket(p)) { free = p; break; }\n  catch (java.io.IOException ignored) {}\n}\nif (free == -1) throw new IllegalStateException(\"No free port in \" + minPort + \"-\" + maxPort);","typeGuard":null,"tryCatchPattern":"try { server.start(); } catch (IOException e) {\n  if (e.getMessage().contains(\"No free port\")) { widenRangeOrPickStaticPort(); } else throw e;\n}","preventionTips":["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"],"tags":["network","port-exhaustion","server-startup","java"],"backgroundTag":"address-already-in-use","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}