Skip to content

RedisCluster: Couldn't map cluster keyspace using any provided seed. Redis->connect works #1864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Diamonds0a opened this issue Oct 20, 2020 · 9 comments
Labels

Comments

@Diamonds0a
Copy link

Diamonds0a commented Oct 20, 2020

I have a local redis cluster running (note that an IP is not provided in CLUSTER SLOTS, is this normal?):

redis-cli -h 127.0.0.2 -p 6379 -a fa^ke^key -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.2:6379> CLUSTER SLOTS
1) 1) (integer) 0
   2) (integer) 16383
   3) 1) ""
      2) (integer) 6379
      3) "55a91fc49daa4477063973c1d039d6c8949c5888"
127.0.0.2:6379> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:1
cluster_size:1
cluster_current_epoch:0
cluster_my_epoch:0
cluster_stats_messages_sent:0
cluster_stats_messages_received:0
127.0.0.2:6379> exit

With the following PHP script:

<PRE><?php
$host = '127.0.0.2';
$port = 6379;
$hosts = ["$host:$port"];
$auth = 'fa^ke^key';
$options = []; //['stream' => ['verify_peer_name' => false, 'verify_peer' => false]];
$persist = false;
try {
    $redis = new \Redis();
    if ($persist) {
        $redis->pconnect($host, $port, 5, null, 0, 0, $options);
    } else {
        $redis->connect($host, $port, 5, null, 0, 0, $options);
    }
    $redis->auth($auth);
    echo "Single redis connection made\n";
    for ($i = 0; $i < 3; $i += 1) {
        $rand1 = rand(0, 10000000000);
        $rand2 = rand(0, 100000000000);
        $redis->set($rand1, $rand2);
        echo "Set $rand1, $rand2\n";
        $rand_return = $redis->get($rand1);
        echo "Got $rand_return\n";
    }
} catch (Throwable $e) {
    print_r($e);
    die();
}

echo "\n\n\nCluster:\n";

try {
    $obj_cluster = new \RedisCluster(null, $hosts, 1.5, 1.5, $persist, $auth, $options);
    echo "connection made\n";

    $obj_cluster->set('test', time());
    echo 'Found:' . $obj_cluster->get('test');

    for ($i = 0; $i < 3; $i += 1) {
        $obj_cluster->set(rand(0, 10000000000), rand(0, 100000000000));
    }
}
catch (Throwable $e) {
    print_r($e->getMessage());
}

I can connect to it directly using Redis->connect(). However RedisCluster() generates an error.

This is the output of the script:

Single redis connection made
Set 465840909, 21045614151
Got 21045614151
Set 1322671438, 80344850474
Got 80344850474
Set 1643062444, 23508231805
Got 23508231805



Cluster:
Couldn't map cluster keyspace using any provided seed

PHP Info:
Redis Support | enabled
Redis Version | 5.3.2RC2
Redis Sentinel Version | 0.1
Available serializers | php, json

Expected behaviour

Connecting to Redis Cluster in local environment using RedisCluster

Actual behaviour

I'm seeing this behaviour on

  • OS: Ubuntu 16.04.5 LTS
  • Redis: Redis server v=6.0.6 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=d463d609620685c0
  • PHP: 7.3
  • phpredis:5.3.2RC2

Steps to reproduce, backtrace or example script

I've checked

  • [ x ] There is no similar issue from other users
  • [ x ] Issue isn't fixed in develop branch
@Diamonds0a
Copy link
Author

I've tried using the ./test/make-cluster.sh script to make redis, and it fails in the same way:

cwstewart (dev) vagrant@cwstewart-hellosign:/opt/hellofax$ redis-cli -h 127.0.0.1 -p 7000 -c
127.0.0.1:7000> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:13
cluster_size:3
cluster_current_epoch:13
cluster_my_epoch:1
cluster_stats_messages_ping_sent:165
cluster_stats_messages_pong_sent:190
cluster_stats_messages_sent:355
cluster_stats_messages_ping_received:178
cluster_stats_messages_pong_received:165
cluster_stats_messages_meet_received:12
cluster_stats_messages_received:355
127.0.0.1:7000> cluster slots
1) 1) (integer) 0
   2) (integer) 5460
   3) 1) "127.0.0.1"
      2) (integer) 7000
      3) "996ed71f2abf7135971f2dfc47c0b15b15468f5d"
   4) 1) "127.0.0.1"
      2) (integer) 7007
      3) "aa54823566f63a45afa3f4c05780c855bd4c1586"
   5) 1) "127.0.0.1"
      2) (integer) 7006
      3) "aecb9f9dde33103922e505fe22e1b2d6e5f2a705"
   6) 1) "127.0.0.1"
      2) (integer) 7008
      3) "834e184be3eeb77374bec165afb4ad0e62ba7d9f"
   7) 1) "127.0.0.1"
      2) (integer) 7009
      3) "b34092d5a559206cecb192067e010a687c3d3c5a"
2) 1) (integer) 5461
   2) (integer) 10922
   3) 1) "127.0.0.1"
      2) (integer) 7001
      3) "437ba185c3a144835a88be99de0d59bd0919a4ed"
   4) 1) "127.0.0.1"
      2) (integer) 7004
      3) "8796beb94971bb43b64afef611544193c58b9f2d"
   5) 1) "127.0.0.1"
      2) (integer) 7012
      3) "b175321d24a0730b2b30e44cdcb601d8f9437ca1"
   6) 1) "127.0.0.1"
      2) (integer) 7010
      3) "7ff84abbe239846a3e05f4f65c224efeee1f9dc0"
3) 1) (integer) 10923
   2) (integer) 16383
   3) 1) "127.0.0.1"
      2) (integer) 7002
      3) "e42413e1ec9540bd516c012ee91a163ce2475750"
   4) 1) "127.0.0.1"
      2) (integer) 7005
      3) "4545b54f10e7af77ec384bbec4c5434a23f74fa4"
   5) 1) "127.0.0.1"
      2) (integer) 7003
      3) "217ae9185aea3644e20999bef2745dc7949fbf27"
   6) 1) "127.0.0.1"
      2) (integer) 7011
      3) "b2517dd17ad50b7c5b2207b3d7a6546e5e230f42"
127.0.0.1:7000> 

The Script:

<PRE><?php
 $host = '127.0.0.1';
// $host = 'app.dev-hellosign.com';
$port = 7000;
$hosts = ["$host:$port"];
$auth = null; //'fa^ke^key';
$options = []; //['stream' => ['verify_peer_name' => false, 'verify_peer' => false]];
$persist = false; //isset($_GET['p']) ? (bool) $_GET['p'] : false;

echo "\n\n\nCluster:\n";

try {
    $obj_cluster = new \RedisCluster(null, $hosts, 1.5, 1.5, $persist, $auth, $options);
    echo "connection made\n";

    $obj_cluster->set('test', time());
    echo 'Found:' . $obj_cluster->get('test');

    for ($i = 0; $i < 3; $i += 1) {
        $obj_cluster->set(rand(0, 10000000000), rand(0, 100000000000));
    }
}
catch (Throwable $e) {
    print_r($e->getMessage());
}

Output:

Cluster:
Couldn't map cluster keyspace using any provided seed

@Diamonds0a
Copy link
Author

Diamonds0a commented Oct 20, 2020

I found how how to get it to work, but I still have a problem.

If I remove $options from the new \RedisCluster() call, then it will connect. However, I eventually want this to use TLS, which requires the $options array yes? Having $options be null or empty array causes errors.

@michael-grunder
Copy link
Member

michael-grunder commented Oct 20, 2020

Hi @Diamonds0a,

I only scanned the logic quickly but I think this is a bug. That said, I believe you will be able to connect with TLS using the options array. The issue appears to be erroneously setting "ssl://" as the URL scheme if any options are passed at all.

The specific line is here:

scheme = redis_sock->stream_ctx ? "ssl" : "tcp";

When options are passed at all redis_sock->stream_ctx is non-null, even though it's not set to anything.

I'm not sure what the correct fix is but it should be pretty simple.

Edit: To put it another way, not passing SSL options to an unsecured connection should work. Passing SSL options to a TLS secured connection should work. What doesn't work is passing options to an unsecured connection.

@yatsukhnenko
Copy link
Member

@michael-grunder I don't know is this a bug because if you want to use TLS you need to specify stream context options array. Empty array may be used if you don't want to change any default settings.

@yatsukhnenko
Copy link
Member

I think we may allow $options to be passed as NULL

yatsukhnenko added a commit that referenced this issue Oct 21, 2020
Allow `$options` to be passed as `NULL`.
michael-grunder pushed a commit that referenced this issue Oct 21, 2020
Allow `$options` to be passed as `NULL`.
@yatsukhnenko
Copy link
Member

@Diamonds0a could you test 5.3.2? Issue should be fixed

@Diamonds0a
Copy link
Author

Works.

@Diamonds0a
Copy link
Author

FYI I think $redis->connect($host, $port, 5, null, 0, 0, $options); has the same problem. When $options is null.

@yatsukhnenko
Copy link
Member

@Diamonds0a thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants