Skip to content
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

StatefulRedisClusterPubSubConnectionImpl's activated() method will report exception after resubscribe() was call. #2534

Closed
JunRzz opened this issue Oct 24, 2023 · 1 comment
Labels
type: bug A general bug
Milestone

Comments

@JunRzz
Copy link

JunRzz commented Oct 24, 2023

Bug Report

async.clusterMyId().thenAccept(this::setNodeId); in StatefulRedisClusterPubSubConnectionImpl's activated() will failed after
resubscribe(),and the exception was Command CLUSTER not allowed while subscribed. Allowed commands are: [PSUBSCRIBE, QUIT, PUNSUBSCRIBE, SUBSCRIBE, UNSUBSCRIBE, PING]

Current Behavior

I have some codes like this:

 ArrayList<RedisURI> list = new ArrayList<>();
        CharSequence password = "6lFaWttbWlpAZxlPoB8h";
        RedisURI redisUri = RedisURI.create("10.97.213.53", 6379);
        redisUri.setClientName("lettuce-test");
        StaticCredentialsProvider credentialsProvider = new StaticCredentialsProvider(null,
                password.toString().toCharArray());
        redisUri.setCredentialsProvider(credentialsProvider);
        list.add(redisUri);
        RedisClusterClient redisClusterClient = RedisClusterClient.create(list);
        redisClusterClient.addListener(new CommandListener() {
            @Override
            public void commandFailed(CommandFailedEvent event) {
                System.out.printf("Redis command %s failed:%s,",event.getCommand(),event.getCause().getMessage());
            }
        });
        StatefulRedisClusterPubSubConnection<String, String> connection = redisClusterClient.connectPubSub();
        connection.async().subscribe("test");
        connection.addListener(new RedisClusterPubSubListener<String, String>() {
              ....
        });

When I use client kill command to kill this sub connection on redis server,lettuce will reconnecting,and the CommandListener will print error message of cluster myid.

Environment

  • Lettuce version(s): 6.2.1.RELEASE
  • Redis version: 5.0.7

Possible Solution

StatefulRedisClusterPubSubConnectionImpl's resubscribe() set the nodeId at the same time.

@Override
    protected List<RedisFuture<Void>> resubscribe() {

        async().clusterMyId().thenAccept(nodeId -> {
            endpoint.setClusterNode(partitions.getPartitionByNodeId(nodeId));
            setNodeId(nodeId);
        });
        return super.resubscribe();
    }`

StatefulRedisClusterPubSubConnectionImpl's activated() add some check codes

  @Override
    public void activated() {
        super.activated();
        if (!endpoint.isSubscribed()){
            async.clusterMyId().thenAccept(this::setNodeId);
        }
    }
@mp911de mp911de added the type: bug A general bug label Oct 24, 2023
@mp911de mp911de added this to the 6.2.7.RELEASE milestone Oct 24, 2023
mp911de added a commit that referenced this issue Oct 24, 2023
We now eagerly obtain the cluster node identifier, before resubscribing to prevent command failures.
mp911de added a commit that referenced this issue Oct 24, 2023
We now eagerly obtain the cluster node identifier, before resubscribing to prevent command failures.
@mp911de
Copy link
Collaborator

mp911de commented Oct 24, 2023

That's fixed now.

@mp911de mp911de closed this as completed Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants