vitessio/vitess · error

failed to get primary position: %v

Error message

failed to get primary position: %v

What it means

StartBinlogDumpFromCurrent first asks the connected primary for its current replication position via PrimaryPosition() (typically a SHOW MASTER/ BINARY LOG STATUS query). If that query fails, no dump can be started, so it returns this wrapped error with nil channels. It indicates the position could not be established before streaming began.

Source

Thrown at go/vt/binlog/binlog_connection.go:111

		return nil, err
	}
	// Tell the server that we understand the format of events
	// that will be used if binlog_checksum is enabled on the server.
	if _, err := conn.ExecuteFetch("SET @source_binlog_checksum = @@global.binlog_checksum, @master_binlog_checksum=@@global.binlog_checksum", 0, false); err != nil {
		return nil, fmt.Errorf("failed to set @source_binlog_checksum=@@global.binlog_checksum: %v", err)
	}

	return conn, nil
}

// StartBinlogDumpFromCurrent requests a replication binlog dump from
// the current position.
func (bc *BinlogConnection) StartBinlogDumpFromCurrent(ctx context.Context) (replication.Position, <-chan mysql.BinlogEvent, <-chan error, error) {
	ctx, bc.cancel = context.WithCancel(ctx)

	position, err := bc.PrimaryPosition()
	if err != nil {
		return replication.Position{}, nil, nil, fmt.Errorf("failed to get primary position: %v", err)
	}

	c, e, err := bc.StartBinlogDumpFromPosition(ctx, "", position)
	return position, c, e, err
}

// StartBinlogDumpFromPosition requests a replication binlog dump from
// the replication source mysqld (typically the primary server in the cluster)
// at the given Position and then sends binlog
// events to the provided channel.
// The stream will continue in the background, waiting for new events if
// necessary, until the connection is closed, either by the replication source or
// by canceling the context.
//
// Note the context is valid and used until eventChan is closed.
func (bc *BinlogConnection) StartBinlogDumpFromPosition(ctx context.Context, binlogFilename string, startPos replication.Position) (<-chan mysql.BinlogEvent, <-chan error, error) {
	ctx, bc.cancel = context.WithCancel(ctx)

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Inspect the wrapped %v error: reconnect (NewBinlogConnection) and retry StartBinlogDumpFromCurrent if it is a connection error.
  2. Grant the replication user REPLICATION CLIENT (and REPLICATION SLAVE/REPLICATION REPLICA) privileges.
  3. On MySQL 8.4+/newer flavors, verify the server supports the status statement PrimaryPosition uses; use the correct flavor.
  4. Check server logs for errors at the time of the query to rule out primary-side crashes.
Defensive patterns

Strategy: retry

Validate before calling

// preflight: confirm the replication user can read the primary position
qr, err := conn.ExecuteFetch("SHOW BINARY LOG STATUS", 1, false) // or SHOW MASTER STATUS on older versions
if err != nil {
	return fmt.Errorf("replication user cannot read primary position: %w", err)
}

Try / catch

pos, chans, err := bc.StartBinlogDumpFromCurrent(ctx)
if err != nil && strings.Contains(err.Error(), "failed to get primary position") {
	// reconnect and retry after backoff; check grants if it persists
}

Prevention

When it happens

Trigger: Calling BinlogConnection.StartBinlogDumpFromCurrent when the underlying PrimaryPosition() query fails — connection lost, server error, or the primary refuses the status query for this user.

Common situations: Primary failover/crash between connect and position query; replication user lacking REPLICATION CLIENT privilege; version mismatch where the status statement name differs (e.g. SHOW MASTER STATUS removed in MySQL 8.4+).

Related errors


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