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

ReadTimeout doesn't seem to work #2305

Closed
aawgit opened this issue Dec 5, 2022 · 5 comments
Closed

ReadTimeout doesn't seem to work #2305

aawgit opened this issue Dec 5, 2022 · 5 comments

Comments

@aawgit
Copy link

aawgit commented Dec 5, 2022

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

ReadTimeout value used in the FailoverOptions for redis.NewFailoverClient to connect to a redis sentinel doesn't seem to have an effect.

Expected Behavior

If the read operation is taking more time than the ReadTimeout value, it should return an error.

Current Behavior

ReadTimeout exceeds, but no error is returned.

Possible Solution

Steps to Reproduce

  1. Connect to a redis sentinel with a ReadTimeout value defined. When the value is smaller, it's easier to reproduce. In the example, I've used 30 microseconds
  2. Do a read operation which takes more than the ReadTimeout and observe the result

Code to reproduce:

`package main

import (
"fmt"
"github.com/go-redis/redis"
"time"
)

func main() {
master := "mymaster"
SentinelServers := []string{"localhost:26379"}
Password := ""
PoolSize := 9
DB := 11
client := redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: master,
SentinelAddrs: SentinelServers,
Password: Password,
PoolSize: PoolSize,
DB: DB,
ReadTimeout: time.Duration(30) * time.Microsecond,
})

res, err := client.Ping().Result()
if err != nil {
	fmt.Printf("Ping error %s\n", err)
}
fmt.Println(res)

key := "key2"
value := "val2"
err = client.Set(key, value, time.Duration(30)*time.Second).Err()
if err != nil {
	fmt.Printf("Writing error %s\n", err)
}

start := time.Now()
val, err := client.Get(key).Result()
if err != nil {
	fmt.Printf("Reading error %s\n", err)
	return
}
elapsed := time.Since(start)
fmt.Printf("Cache read in %s\n", elapsed)
if err != nil {
	fmt.Println(err)
}
fmt.Println(val)

}
`

Context (Environment)

There are occasions where the read operations take up to 10s to complete. Our aim is to unblock such operations by using the ReadTimeout value.

  • module version: github.com/go-redis/redis v6.15.9+incompatible
  • redis version: 7.0 (docker.io/bitnami/redis-sentinel:7.0)

Detailed Description

Possible Implementation

@monkey92t
Copy link
Collaborator

v6 is too old version, you may consider v8/v9?

@aawgit
Copy link
Author

aawgit commented Jan 2, 2023

@monkey92t Thanks. I tried using v9, but it made no difference.

@monkey92t
Copy link
Collaborator

FailoverClient will try to obtain a valid redis-server from multiple sentinel, if FailoverClient only tries once, then it is no different from Client.

@aawgit
Copy link
Author

aawgit commented Jan 3, 2023

@monkey92t Would you please explain it's impact on this issue?

@monkey92t
Copy link
Collaborator

Sentinel needs to obtain redis-server from sentinel-server to execute commands:

client -> cmd -> sentinel -> redis-server -> write cmd to redis-server -> read response from redis-server

Sentinel will try to get redis-server from multiple sentinel-servers. This is a redis command. If it fails (ReadTimeout), it will try other sentinel-servers, so you will feel that ReadTimeout is invalid.
And when redis-server fails to execute a command, you get an error.
So, when you execute the command, it will feel like it took longer than ReadTimeout

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

2 participants