XTLS/Xray-core · error

invalid portMap: {}

Error message

invalid portMap: {}

What it means

Thrown while building a dokodemo-door inbound config when an entry of 'portMap' cannot be split into host:port by net.SplitHostPort. Each portMap entry must be a "from:to" address pair where the port part is parseable; the underlying SplitHostPort error is attached as the base cause. It fires during config Build() before the inbound starts.

Source

Thrown at infra/conf/dokodemo.go:41

	if v.Network != nil {
		v.AllowedNetwork = v.Network
	}
	if v.Address != nil {
		v.RewriteAddress = v.Address
	}
	if v.Port != 0 {
		v.RewritePort = v.Port
	}
	config := new(dokodemo.Config)
	config.AllowedNetworks = v.AllowedNetwork.Build()
	if v.RewriteAddress != nil {
		config.RewriteAddress = v.RewriteAddress.Build()
	}
	config.RewritePort = uint32(v.RewritePort)
	config.PortMap = v.PortMap
	for _, v := range config.PortMap {
		if _, _, err := net.SplitHostPort(v); err != nil {
			return nil, errors.New("invalid portMap: ", v).Base(err)
		}
	}
	config.FollowRedirect = v.FollowRedirect
	config.UserLevel = v.UserLevel
	return config, nil
}

View on GitHub (pinned to 7d214f8b09)

Solutions

  1. Format every portMap entry as "sourcePort:destHost:destPort" or the documented "host:port" pair so SplitHostPort succeeds (e.g. "80:127.0.0.1:8080").
  2. Wrap IPv6 literals in brackets: "[::1]:443".
  3. Inspect the wrapped base error — it is the exact net.SplitHostPort reason (too many colons, missing port, etc.).

Example fix

// before
"portMap": ["80"]

// after
"portMap": ["80:127.0.0.1:8080"]
Defensive patterns

Strategy: validation

Validate before calling

for _, pm := range portMap {
    if _, _, err := net.SplitHostPort(pm); err != nil {
        return fmt.Errorf("invalid portMap %q: %w", pm, err)
    }
}

Prevention

When it happens

Trigger: A dokodemo inbound with "portMap": ["80"] (missing colon / port), ":::80" malformed IPv6, or an entry with only a port and no destination. Any value for which net.SplitHostPort returns an error triggers it.

Common situations: Writing portMap entries as bare ports ("1080") instead of address pairs; malformed IPv6 literals missing brackets; trailing colons or whitespace.

Related errors


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/faeabc16242b7c21. Report an issue: GitHub.