temporalio/temporal · error

rowsAffected returned error for shardID %v: %v

Error message

rowsAffected returned error for shardID %v: %v

What it means

In the SQL shard store's create-shard path, after inserting the shard row the driver's result.RowsAffected() is called to confirm success; if that call itself errors, the shardID and underlying driver error are wrapped and returned. The insert may still have succeeded but cannot be verified.

Source

Thrown at common/persistence/sql/shard.go:106

			tx,
			request.ShardID,
			request.PreviousRangeID,
			m.logger,
		); err != nil {
			return err
		}
		result, err := tx.UpdateShards(ctx, &sqlplugin.ShardsRow{
			ShardID:      request.ShardID,
			RangeID:      request.RangeID,
			Data:         request.ShardInfo.Data,
			DataEncoding: request.ShardInfo.EncodingType.String(),
		})
		if err != nil {
			return err
		}
		rowsAffected, err := result.RowsAffected()
		if err != nil {
			return fmt.Errorf("rowsAffected returned error for shardID %v: %v", request.ShardID, err)
		}
		if rowsAffected != 1 {
			return fmt.Errorf("rowsAffected returned %v shards instead of one", rowsAffected)
		}
		return nil
	})
}

func (m *sqlShardStore) AssertShardOwnership(
	ctx context.Context,
	request *persistence.AssertShardOwnershipRequest,
) error {
	// AssertShardOwnership is not implemented for sql shard store
	return nil
}

// initiated by the owning shard
func lockShard(

View on GitHub (pinned to bde624efd1)

Solutions

  1. Read the wrapped driver error in the message for the root cause and fix connectivity or driver configuration.
  2. Upgrade the database driver (go-sql-driver/mysql, lib/pq) to a version with correct RowsAffected support.
  3. Confirm the backend is officially supported; proxies like some connection poolers can strip affected-row info.
  4. Retry shard creation; if the insert actually committed, the next attempt should take the existing-shard path instead.
Defensive patterns

Strategy: retry

Try / catch

if err := createShard(ctx); err != nil {
    if strings.Contains(err.Error(), "rowsAffected returned error for shardID") {
        // transient driver/connection issue; retry with backoff
        return retryWithBackoff(createShard)
    }
    return err
}

Prevention

When it happens

Trigger: Creating a shard row (no existing shard) where the SQL driver's RowsAffected fails right after the INSERT — typically a driver limitation or a broken/dead connection immediately after execution.

Common situations: Unsupported or misbehaving database driver; connection killed between statement execution and RowsAffected; custom drivers (e.g., some proxies/wrappers) that don't implement affected-row counts.

Related errors


AI-assisted analysis of temporalio/temporal@bde624efd1 (2026-09-01). Data as JSON: /api/errors/7d37396c1aeeed86. Report an issue: GitHub.