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

a funny bug about cluster redis "NewGR" #815

Open
ALEX-yinhao opened this issue Aug 27, 2024 · 0 comments
Open

a funny bug about cluster redis "NewGR" #815

ALEX-yinhao opened this issue Aug 27, 2024 · 0 comments

Comments

@ALEX-yinhao
Copy link

ALEX-yinhao commented Aug 27, 2024

about cluster redis, if you have a password with redis, one funny bug will be happend.
here is the code about broker NewGR and backend NewGR

broker NewGR :

var password string
parts := strings.Split(addrs[0], "@")
if len(parts) >= 2 {
	// with password
	password = strings.Join(parts[:len(parts)-1], "@")
	addrs[0] = parts[len(parts)-1] // addr is the last one without @
}

backend NewGR

parts := strings.Split(addrs[0], "@")
if len(parts) >= 2 {
	// with passwrod
	b.password = strings.Join(parts[:len(parts)-1], "@")
	addrs[0] = parts[len(parts)-1] // addr is the last one without @
}

the cluster redis example

cnf := &machineryConfig.Config{
	DefaultQueue:    "machinery_tasks",
	ResultsExpireIn: 3600,
	Redis: &machineryConfig.RedisConfig{
		MaxIdle:                300,
		IdleTimeout:            240,
		ReadTimeout:            15,
		WriteTimeout:           15,
		ConnectTimeout:         15,
		NormalTasksPollPeriod:  1000,
		DelayedTasksPollPeriod: 500,
	},
}

if config.Type == "cluster" {
	addrs := make([]string, 0)
	for k, v := range config.ClusterAddrs {
		if k == 0 {
			addrs = append(addrs, config.Password+"@"+v)
		} else {
			addrs = append(addrs, v)
		}
	}
	fmt.Println(addrs)
	cnf.Redis.ClusterMode = true
	broker := redisbroker.NewGR(cnf, addrs, 0)
	backend := redisbackend.NewGR(cnf, addrs, 0)
	lock := eagerlock.New()
	server = machinery.NewServerWithBrokerBackendLock(cnf, broker, backend, lock)
  }

if we dont see the code of NewGR , we will use redis addrs in broker and backend.
But in the borker NewGR, it will change the array "addrs" ,cut the password of redis, and then the backend NewGR cant find the password in the array "addrs"

also, the password only cut the first one of the "addrs".

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

1 participant