vitessio/vitess · error

SplitHostPort: missing port in %q

Error message

SplitHostPort: missing port in %q

What it means

SplitHostPort wraps net.SplitHostPort with a naive fallback split. This error is returned when the address contains no ':' at all, so neither proper nor naive parsing can find a port. It indicates the caller passed a bare hostname/IP without a port component.

Source

Thrown at go/netutil/netutil.go:39

	"bytes"
	"fmt"
	"net"
	"os"
	"sort"
	"strconv"
	"strings"
)

// SplitHostPort is an alternative to net.SplitHostPort that also parses the
// integer port. In addition, it is more tolerant of improperly escaped IPv6
// addresses, such as "::1:456", which should actually be "[::1]:456".
func SplitHostPort(addr string) (string, int, error) {
	host, port, err := net.SplitHostPort(addr)
	if err != nil {
		// If the above proper parsing fails, fall back on a naive split.
		i := strings.LastIndex(addr, ":")
		if i < 0 {
			return "", 0, fmt.Errorf("SplitHostPort: missing port in %q", addr)
		}
		host = addr[:i]
		port = addr[i+1:]
	}
	p, err := strconv.ParseUint(port, 10, 16)
	if err != nil {
		return "", 0, fmt.Errorf("SplitHostPort: can't parse port %q: %v", port, err)
	}
	return host, int(p), nil
}

// JoinHostPort is an extension to net.JoinHostPort that also formats the
// integer port.
func JoinHostPort(host string, port int32) string {
	return net.JoinHostPort(host, strconv.FormatInt(int64(port), 10))
}

// FullyQualifiedHostname returns the FQDN of the machine.

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Append the port to the address, e.g. "localhost:15002" instead of "localhost"
  2. Fix the config flag/env var that supplies the address so it always includes the port
  3. Use netutil.JoinHostPort(host, port) when constructing addresses programmatically
  4. Validate the address contains a colon before calling SplitHostPort

Example fix

// before
host, port, err := netutil.SplitHostPort("localhost")
// after
host, port, err := netutil.SplitHostPort("localhost:15002")
Defensive patterns

Strategy: validation

Validate before calling

func validateAddr(addr string) error {
    if !strings.Contains(addr, ":") {
        return fmt.Errorf("address %q must include a port (host:port)", addr)
    }
    return nil
}
validateAddr(addr) // call before netutil.SplitHostPort

Try / catch

host, port, err := netutil.SplitHostPort(addr)
if err != nil {
    return fmt.Errorf("invalid address %q: %w", addr, err)
}

Prevention

When it happens

Trigger: Calling netutil.SplitHostPort (directly or via Connect, FindReplicas) with an address like "localhost" or "10.0.0.1" that has no ":port" suffix.

Common situations: Config files or command-line flags where the port was omitted (e.g. vtctld or tablet address configured as host only); template-generated addresses where the port field was empty; users forgetting the port when entering replica addresses.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/d7fedd2264925989. Report an issue: GitHub.