ClusterOptions: ReadTimeout/WriteTimeout -1 gives node clients the 5s default
Expected Behavior
ReadTimeout: -1 / WriteTimeout: -1 on ClusterOptions means no timeout, same as on Options. Each node client should end up with a timeout of 0.
Current Behavior
Node clients use the 5s default. ClusterOptions.init turns -1 into 0, and then Options.init on each node client turns that 0 into 5s. So any command that takes longer than 5s fails with an i/o timeout even with -1. The same happens through UniversalOptions when it builds a cluster client.
-2 works on clusters. Ring and the failover client pass -1 through untouched, so they work too.
Possible Solution
Don't let the node clients see the already-normalized 0. For example, map 0 back to -1 when building the node options in newClusterNodeWithNodeAddress, so Options.init handles it like it does for a plain client.
Steps to Reproduce
- Start a Redis server with
--enable-debug-command yes(a single node is enough, usingClusterSlots). - Run:
ctx := context.Background()
rdb := redis.NewClusterClient(&redis.ClusterOptions{
ClusterSlots: func(ctx context.Context) ([]redis.ClusterSlot, error) {
return []redis.ClusterSlot{{Start: 0, End: 16383, Nodes: []redis.ClusterNode{{Addr: "127.0.0.1:6379"}}}}, nil
},
ReadTimeout: -1,
WriteTimeout: -1,
})
_ = rdb.ForEachShard(ctx, func(ctx context.Context, shard *redis.Client) error {
fmt.Println(shard.Options().ReadTimeout, shard.Options().WriteTimeout)
return nil
})
fmt.Println(rdb.Do(ctx, "DEBUG", "SLEEP", "6").Err())- It prints
5s 5s, thenread tcp ...: i/o timeout. - With
redis.NewClient(&redis.Options{ReadTimeout: -1, ...})the same command succeeds.
Context (Environment)
go-redis master (9.23.0-beta.1), Go 1.27. Found while documenting the timeout options on UniversalOptions (#4045).
Detailed Description
ClusterOptions.init normalizes the timeouts for the cluster's own pipeline and tx paths, but clientOptions() forwards the normalized values to NewClient, which normalizes them a second time. The mapping isn't idempotent for -1.
Possible Implementation
I have a small fix with a unit test and will open a PR.
Source: redis/go-redis