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

redis client in ipv6 environment is not working #2978

Open
panagiotspappas opened this issue Apr 18, 2024 · 15 comments
Open

redis client in ipv6 environment is not working #2978

panagiotspappas opened this issue Apr 18, 2024 · 15 comments

Comments

@panagiotspappas
Copy link

Issue tracker is used for reporting bugs and discussing new features. Please use
stackoverflow for supporting issues.

When using redis-client 9.5.1 we have issue at ipv6 environment.

We have a kubernetes environment and we are using redis cluster.

In our application we first create a new redis client

client = redis.NewClusterClient(opt)

with address redisdb service name: xxx-crdb.test.svc.cluster.local.:6379

Then we are checking connection with
resp, err := c.redisClient.Ping(context.Background()).Result()

Ping is successful.

After that are are creating a consumer group:
c.redisClient.XGroupCreateMkStream(context.Background(), streamName, groupName, start).Err()

The later command fails with redis-client 9.5.1 with error:
dial tcp: address fd01:abcd::7d03:6379: too many colons in address.

We have many retries and it constantly fails.

With redis-client 9.3.0 it fails once and then it succeeds.

@monkey92t
Copy link
Collaborator

Thank you for your feedback. go-redis has not been adapted for IPv6. Are you interested in submitting a PR?

@panagiotspappas
Copy link
Author

Hi, I have a question.
How come ping succeeds and the creation of group fails?
I mean, don't these two commands use/establish the same connection?
Is it possible to point to the differences between Ping and XGroupCreateMkStream, regarding to the connection?

@monkey92t
Copy link
Collaborator

I'm not sure where the problem lies. In cluster mode, go-redis perceives all nodes within the cluster through the cluster slots command, using their IP addresses and ports to establish connections. However, I've checked all operations involving IP addresses, and they all use net.JoinHostPort(), which requires an IPv6 Redis cluster for testing.

@monkey92t
Copy link
Collaborator

Can you print the result of cluster slots?

See: https://redis.io/docs/latest/commands/cluster-slots/

@daviddzxy
Copy link
Contributor

I also encountered this error. Seems like moved, ask, addr = isMovedError(lastErr) in func (c *ClusterClient) process(ctx context.Context, cmd Cmder) error function returns IPv6 in bad format. I will try to make PR with a fix.

@daviddzxy
Copy link
Contributor

Here is the PR @monkey92t

@monkey92t
Copy link
Collaborator

monkey92t commented Apr 25, 2024

I currently do not have more devices to build an IPv6 cluster for testing. I am not sure about the data format of MOVE ADDR. If it looks like MOVE fd01:abcd::7d03:6379, then it is not a valid IPv6 format. However, after Redis fixes it, it may look like MOVE [fd01:abcd::7d03]:6379, which could cause compatibility issues.

@monkey92t
Copy link
Collaborator

redis ipv6 issue redis/redis#6238

It looks like we can make some compatibility adjustments to handle both fd01:abcd::7d03:6379 and [fd01:abcd::7d03]:6379 types of IPv6 addresses properly. @daviddzxy, can you continue?

@monkey92t
Copy link
Collaborator

Moreover, under normal circumstances, go-redis should not encounter MOVE. Before sending a command, go-redis calculates the node for the key and sends the Redis command to that node. This type of issue only occurs when Redis is reassigning slots, and it seems we triggered another bug that caused slot calculation errors.

@daviddzxy
Copy link
Contributor

redis ipv6 issue redis/redis#6238

It looks like we can make some compatibility adjustments to handle both fd01:abcd::7d03:6379 and [fd01:abcd::7d03]:6379 types of IPv6 addresses properly. @daviddzxy, can you continue?

Sure, I ll update the PR.

@daviddzxy
Copy link
Contributor

I updated the PR. @monkey92t

@daviddzxy
Copy link
Contributor

daviddzxy commented Apr 26, 2024

I have done some more debugging. It turns out that when XGroupCreateMkStream function is called the func cmdFirstKeyPos(cmd Cmder) int function returns wrong pos number (It returns 1 instead of 2). As a result of this, the function func Slot(key string) int will receive "create" key argument. This causes incorrectly calculated slot number and therefore we get MOVED error. @monkey92t

@daviddzxy
Copy link
Contributor

Should I create another issue for this bug? I plan to make a PR with a fix later today.

@monkey92t
Copy link
Collaborator

Should I create another issue for this bug? I plan to make a PR with a fix later today.

OK!

@daviddzxy
Copy link
Contributor

Here is the issue

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

No branches or pull requests

3 participants