t8y2/dbx · error
ZooKeeper connection is nil
Error message
ZooKeeper connection is nil
What it means
newProtocolZooKeeperClient wraps an established net.Conn into the protocol-level ZooKeeper client and immediately rejects a nil connection. This guards against constructing a client whose subsequent writes would panic on nil. Note the same error symbol exists in both hive-go and argo-go driver copies.
Source
Thrown at agents/drivers/hive-go/zookeeper_protocol.go:143
events := make(chan zk.Event, 1)
events <- zk.Event{State: zk.StateHasSession, Server: address}
close(events)
return client, events, nil
}
return nil, nil, fmt.Errorf("connect and authenticate to ZooKeeper: %s", strings.Join(failures, "; "))
}
type protocolZooKeeperClient struct {
connection net.Conn
timeout time.Duration
xid int32
mutex sync.Mutex
closed bool
}
func newProtocolZooKeeperClient(connection net.Conn, timeout time.Duration) (*protocolZooKeeperClient, error) {
if connection == nil {
return nil, errors.New("ZooKeeper connection is nil")
}
if timeout <= 0 {
timeout = defaultConnectTimeout
}
client := &protocolZooKeeperClient{connection: connection, timeout: timeout}
request := &zooKeeperEncoder{}
request.int32(zooKeeperProtocolVersion)
request.int64(0)
request.int32(zooKeeperTimeoutMillis(timeout))
request.int64(0)
request.bytes(make([]byte, 16))
if err := client.writeFrame(request.data()); err != nil {
return nil, fmt.Errorf("send ZooKeeper connect request: %w", err)
}
response, err := client.readFrame()
if err != nil {
return nil, fmt.Errorf("read ZooKeeper connect response: %w", err)
}View on GitHub (pinned to c0390bff16)
Solutions
- Always check the error from the dial/connect step before calling newProtocolZooKeeperClient
- Fix callers that ignore the (conn, err) pair from connectKerberosZooKeeper/connectZooKeeper
- Ensure dial helpers never return nil conn with nil error
- In tests, pass a real or stub net.Conn (e.g. net.Pipe) rather than nil
Example fix
// before
conn, _, _ := connectKerberosZooKeeper(ctx, servers, timeout, tls, cfg)
client, err := newProtocolZooKeeperClient(conn, timeout)
// after
conn, _, err := connectKerberosZooKeeper(ctx, servers, timeout, tls, cfg)
if err != nil {
return err
}
client, err := newProtocolZooKeeperClient(conn, timeout) Defensive patterns
Strategy: type-guard
Validate before calling
// Go
if conn == nil {
return errors.New("cannot create ZooKeeper client: connection is nil")
} Type guard
// Go
func isLiveConn(c net.Conn) bool { return c != nil }
if isLiveConn(conn) {
client, err := newProtocolZooKeeperClient(conn, timeout)
...
} Prevention
- Never discard errors from dial/connect functions with _
- Return early on connect errors instead of passing conn through
- Keep dial helpers contract: non-nil error implies nil conn
When it happens
Trigger: Calling newProtocolZooKeeperClient with a nil net.Conn — usually because the preceding dial/ZooKeeper connect returned (nil, nil, err) and the error was ignored or the nil conn was passed through unconditionally.
Common situations: Caller does `conn, _, _ := connectKerberosZooKeeper(...)` discarding the error and then builds the client; a helper returns nil conn on a non-error path by mistake; test scaffolding passes a stub that is nil.
Related errors
- ZooKeeper sent an unexpected token after GSSAPI completion
- decode ZooKeeper SASL round %d: %w
- ZooKeeper GSSAPI negotiation exceeded %d rounds
- ZooKeeper response XID %d does not match request XID %d
- ZooKeeper session closed because SASL authentication is requ
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/40ab09f7642f1fe8.
Report an issue: GitHub.