jackc/pgx · error

outside range

Error message

outside range

What it means

parsePort guard: the port string parsed as an integer without error, but the resulting value is 0 — outside the usable TCP port range (1–65535). The port component of the connection string is the faulty input.

Solutions

  1. Use a port between 1 and 65535 (PostgreSQL's default is 5432)
  2. Check for a stray 'port=0' or a malformed host:port pair
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgconn/config.go:1004 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jackc/pgx@ec1a0befd2 (2026-08-04). Data as JSON: /api/errors/39e8e039d58ea97a. Report an issue: GitHub.

Appendix: source

Thrown at pgconn/config.go:1004

	switch sslmode {
	case "allow":
		return []*tls.Config{nil, tlsConfig}, nil
	case "prefer":
		return []*tls.Config{tlsConfig, nil}, nil
	case "require", "verify-ca", "verify-full":
		return []*tls.Config{tlsConfig}, nil
	default:
		panic("BUG: bad sslmode should already have been caught")
	}
}

func parsePort(s string) (uint16, error) {
	port, err := strconv.ParseUint(s, 10, 16)
	if err != nil {
		return 0, err
	}
	if port < 1 || port > math.MaxUint16 {
		return 0, errors.New("outside range")
	}
	return uint16(port), nil
}

func makeDefaultDialer() *net.Dialer {
	// rely on GOLANG KeepAlive settings
	return &net.Dialer{}
}

func makeDefaultResolver() *net.Resolver {
	return net.DefaultResolver
}

func parseConnectTimeoutSetting(s string) (time.Duration, error) {
	timeout, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		return 0, err
	}

View on GitHub (pinned to ec1a0befd2)