Skip to content

RedisCluster: directed rawCommand() may be routed to a replica under FAILOVER_DISTRIBUTE #3017

In review

Description

@tillkruss

Follow-up to #2890. b30ced7 fixed flushdb() and flushall(), but node-directed rawCommand() still inherits a stale c->readonly from the previous read. With FAILOVER_DISTRIBUTE or FAILOVER_DISTRIBUTE_SLAVES, it can be sent to a replica of the given node.

Expected behaviour

rawCommand($master, ...) is sent to $master, like flushdb($master).

Actual behaviour

After a read, it's sent to a replica of $master. FLUSHDB is rejected with READONLY You can't write against a read only replica. and rawCommand() returns false.

PHP_METHOD(RedisCluster, rawcommand) never sets c->readonly, so cluster_sock_write() uses the value left by the previous command. Setting c->readonly = 0 there, as cluster_flush_cmd() now does, would fix it.

I'm seeing this behaviour on

  • OS: macOS 27.2.1 (arm64)
  • Redis: 8.10.3, 3 primaries with 1 replica each
  • PHP: 8.5.12 (NTS)
  • phpredis: 6.4.0RC1 and develop (a17268c)

Steps to reproduce, backtrace or example script

$c = new RedisCluster(null, ['127.0.0.1:7000']);
$c->setOption(RedisCluster::OPT_SLAVE_FAILOVER, RedisCluster::FAILOVER_DISTRIBUTE_SLAVES);

foreach ($c->_masters() as $master) {
    $c->get('foo'); // any read sets `c->readonly = 1`
    var_dump($c->flushdb($master, true)); // bool(true)

    $c->get('foo');
    var_dump($c->rawCommand($master, 'FLUSHDB', 'ASYNC')); // bool(false)
    var_dump($c->getLastError()); // "READONLY You can't write against a read only replica."
    $c->clearLastError();
}

Each replica's INFO commandstats then shows rejected_calls=1 for flushdb.

I've checked

  • There is no similar issue from other users
  • Issue isn't fixed in develop branch

Activity

  1. added a commit that references this issue on Nov 24, 2026
    da5b564
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions