vitessio/vitess · error

bad command line format for zk config

Error message

bad command line format for zk config

What it means

MakeZkConfigFromString panics with 'bad command line format for zk config' when the comma-separated zk server string contains an entry without the required 'serverID@host:port' format — specifically when splitting an entry on '@' does not yield exactly 2 parts. The function converts the CLI string into a ZkConfig for starting/using ZooKeeper.

Source

Thrown at go/vt/zkctl/zkconf.go:150

	return cnfData.String(), nil
}

const GuessMyID = 0

/*
Create a config for this instance.

<server_id>@<hostname>:<leader_port>:<election_port>:<client_port>

If server_id > 1000, then we assume this is a global quorum.
server_id's must be 1-255, global id's are 1001-1255 mod 1000.
*/
func MakeZkConfigFromString(cmdLine string, myID uint32) *ZkConfig {
	zkConfig := NewZkConfig()
	for zki := range strings.SplitSeq(cmdLine, ",") {
		zkiParts := strings.SplitN(zki, "@", 2)
		if len(zkiParts) != 2 {
			panic("bad command line format for zk config")
		}
		zkID := zkiParts[0]
		zkAddrParts := strings.Split(zkiParts[1], ":")
		serverID, _ := strconv.ParseUint(zkID, 10, 32)
		if serverID > 1000 {
			serverID = serverID % 1000
			zkConfig.Global = true
		}
		myID = myID % 1000

		zkServer := zkServerAddr{
			ServerId: uint32(serverID), ClientPort: 2181,
			LeaderPort: 2888, ElectionPort: 3888,
		}
		switch len(zkAddrParts) {
		case 4:
			zkServer.ClientPort, _ = strconv.Atoi(zkAddrParts[3])
			fallthrough

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Fix the command line so each comma-separated entry is 'serverID@host:port', e.g. '1@zk1:2181,2@zk2:2181,3@zk3:2181'.
  2. Remove empty entries / stray commas from the string.
  3. Verify the flag value with the exact documented format before launch (count of '@' equals number of entries).

Example fix

// before
MakeZkConfigFromString("zk1:2181,zk2:2181", myID)
// after
MakeZkConfigFromString("1@zk1:2181,2@zk2:2181", myID)
Defensive patterns

Strategy: validation

Validate before calling

func validZkArg(s string) bool {
    for _, part := range strings.Split(s, ",") {
        if strings.Count(part, "@") != 1 || part == "" {
            return false
        }
    }
    return true
}
if !validZkArg(cmdLine) {
    return errors.New("zk config must be serverID@host:port,serverID@host:port")
}

Try / catch

defer func() {
    if r := recover(); r != nil {
        if r == "bad command line format for zk config" {
            log.Fatalf("invalid -zk argument; expected serverID@host:port entries")
            return
        }
        panic(r)
    }
}()

Prevention

When it happens

Trigger: Calling MakeZkConfigFromString with an entry missing '@', e.g. '1@host:2181,host2:2181' or an empty entry from a trailing comma '1@h:2181,'.

Common situations: Typo in vtctld/vttablet -zk_server args (missing @); copy-pasting a host list without server IDs; stray or leading/trailing commas; forgetting the numeric server ID prefix.

Related errors


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