{"record":{"id":"6e72f2c3b6fd432a","repo":"abiosoft/colima","slug":"no-available-port-found-in-range-d-d","errorCode":null,"errorMessage":"no available port found in range %d-%d","messagePattern":"no available port found in range (.+?)-(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/model.go","lineNumber":197,"sourceCode":"\t\t\treturn err\n\t\t}\n\n\t\t// Ensure the model is available (pull if necessary) - this happens outside alternate screen\n\t\tnormalizedModel, err := runner.EnsureModel(modelName)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t// Determine the port to use\n\t\tport := modelCmdArgs.ServePort\n\t\tportExplicitlySet := cmd.Flags().Changed(\"port\")\n\n\t\t// If port was not explicitly set, find an available port starting from the default\n\t\tconst maxPortAttempts = 20\n\t\tif !portExplicitlySet {\n\t\t\tavailablePort, found := util.FindAvailablePort(port, maxPortAttempts)\n\t\t\tif !found {\n\t\t\t\treturn fmt.Errorf(\"no available port found in range %d-%d\", port, port+maxPortAttempts-1)\n\t\t\t}\n\t\t\tif availablePort != port {\n\t\t\t\tfmt.Printf(\"Port %d is in use, using port %d instead\\n\", port, availablePort)\n\t\t\t}\n\t\t\tport = availablePort\n\t\t} else {\n\t\t\t// User explicitly set the port, check if it's available\n\t\t\tif _, found := util.FindAvailablePort(port, 1); !found {\n\t\t\t\treturn fmt.Errorf(\"port %d is already in use\", port)\n\t\t\t}\n\t\t}\n\n\t\t// Build header for alternate screen\n\t\tseparator := \"────────────────────────────────────────\"\n\t\theader := fmt.Sprintf(\"Colima - Model Server (Ctrl-C to stop)\\nWeb UI & API at http://localhost:%d\\n%s\", port, separator)\n\n\t\t// Run in alternate screen with header\n\t\treturn terminal.WithAltScreen(func() error {","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/cmd/model.go#L179-L215","documentation":"`colima model serve` without an explicit --port scans 20 consecutive TCP ports starting from the default (util.FindAvailablePort binds and releases each port via net.Listen to test it). If all 20 candidate ports are occupied on the host, no bindable port exists and the serve command aborts before starting the model server.","triggerScenarios":"Host already running 20+ services covering the whole candidate range (other model servers, dev servers, containers publishing those ports); parallel `colima model serve` invocations each consuming a port; the default port occupied by a wedged process plus a busy neighborhood above it.","commonSituations":"Dev machines with many published container ports; several colima model serve instances across profiles; a previous serve process that did not release its port (hung/zombie).","solutions":["Free or pick a port explicitly: `colima model serve --port <port>` after checking `lsof -i tcp:<port>`","Kill stale listeners in the range (lsof -nP -i tcp:<defaultPort>-<defaultPort+19> | grep LISTEN)","Run fewer concurrent model servers, or serve on a deliberately high, rarely-contended port"],"exampleFix":"# before\n$ colima model serve\nerror: no available port found in range 12434-12453\n\n# after\n$ lsof -nP -i tcp:12434-12453   # find and kill blockers, then:\n$ colima model serve --port 18080","handlingStrategy":"retry","validationCode":"// probe the scan range yourself, then pass --port explicitly\nfor port := defaultPort; port < defaultPort+20; port++ {\n    if l, err := net.Listen(\"tcp\", fmt.Sprintf(\":%d\", port)); err == nil {\n        l.Close()\n        break // use: colima model serve --port <port>\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := serveCmd.Execute(); err != nil {\n    if strings.Contains(err.Error(), \"no available port found in range\") {\n        // free a port (or pick a high one) and retry with --port\n    }\n}","preventionTips":["Prefer an explicit --port in automation over relying on the 20-port auto-scan","Free stale listeners (lsof -nP -i tcp:<range>) before serving","Serve on high, rarely-contended ports in busy dev environments"],"tags":["colima","llm","network","ports","cli"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}