abiosoft/colima · error

no available port found in range %d-%d

Error message

no available port found in range %d-%d

What it means

`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.

Source

Thrown at cmd/model.go:197

			return err
		}

		// Ensure the model is available (pull if necessary) - this happens outside alternate screen
		normalizedModel, err := runner.EnsureModel(modelName)
		if err != nil {
			return err
		}

		// Determine the port to use
		port := modelCmdArgs.ServePort
		portExplicitlySet := cmd.Flags().Changed("port")

		// If port was not explicitly set, find an available port starting from the default
		const maxPortAttempts = 20
		if !portExplicitlySet {
			availablePort, found := util.FindAvailablePort(port, maxPortAttempts)
			if !found {
				return fmt.Errorf("no available port found in range %d-%d", port, port+maxPortAttempts-1)
			}
			if availablePort != port {
				fmt.Printf("Port %d is in use, using port %d instead\n", port, availablePort)
			}
			port = availablePort
		} else {
			// User explicitly set the port, check if it's available
			if _, found := util.FindAvailablePort(port, 1); !found {
				return fmt.Errorf("port %d is already in use", port)
			}
		}

		// Build header for alternate screen
		separator := "────────────────────────────────────────"
		header := fmt.Sprintf("Colima - Model Server (Ctrl-C to stop)\nWeb UI & API at http://localhost:%d\n%s", port, separator)

		// Run in alternate screen with header
		return terminal.WithAltScreen(func() error {

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Free or pick a port explicitly: `colima model serve --port <port>` after checking `lsof -i tcp:<port>`
  2. Kill stale listeners in the range (lsof -nP -i tcp:<defaultPort>-<defaultPort+19> | grep LISTEN)
  3. Run fewer concurrent model servers, or serve on a deliberately high, rarely-contended port

Example fix

# before
$ colima model serve
error: no available port found in range 12434-12453

# after
$ lsof -nP -i tcp:12434-12453   # find and kill blockers, then:
$ colima model serve --port 18080
Defensive patterns

Strategy: retry

Validate before calling

// probe the scan range yourself, then pass --port explicitly
for port := defaultPort; port < defaultPort+20; port++ {
    if l, err := net.Listen("tcp", fmt.Sprintf(":%d", port)); err == nil {
        l.Close()
        break // use: colima model serve --port <port>
    }
}

Try / catch

if err := serveCmd.Execute(); err != nil {
    if strings.Contains(err.Error(), "no available port found in range") {
        // free a port (or pick a high one) and retry with --port
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15). Data as JSON: /api/errors/6e72f2c3b6fd432a. Report an issue: GitHub.