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

v1.0.20 introduced occasional panic when connecting to non-available Redis Cluster #543

Closed
FZambia opened this issue May 10, 2024 · 2 comments · Fixed by #544
Closed

v1.0.20 introduced occasional panic when connecting to non-available Redis Cluster #543

FZambia opened this issue May 10, 2024 · 2 comments · Fixed by #544

Comments

@FZambia
Copy link
Contributor

FZambia commented May 10, 2024

Hello @rueian !

Found a regression in rueidis while testing centrifuge. It triggers a panic when initializing rueidis.Client while Redis Cluster is not available. Before v1.0.20 there was no panic.

To reproduce, add test like this:

func TestConnectToNonAvailableCluster(t *testing.T) {
	_, err := NewClient(ClientOption{
		InitAddress: []string{"127.0.0.1:3000", "127.0.0.1:3001", "127.0.0.1:3002"},
	})
	if err == nil {
		t.Fatal("expected connect error")
	}
}

Do not run Redis Cluster at all (!)

Then with the help of stress tool:

go test -c
stress ./rueidis.test -test.run TestConnectToNonAvailableCluster

You should quickly see panic like this:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1009ec070]

goroutine 52 [running]:
github.com/redis/rueidis.(*clusterClient).lazyRefresh(...)
	/Users/alexander.emelin/centrifugal/rueidis/cluster.go:174
github.com/redis/rueidis.newClusterClient.func1.1({0x0?, 0x0?})
	/Users/alexander.emelin/centrifugal/rueidis/cluster.go:118 +0x60
github.com/redis/rueidis.(*mux)._pipe(0x140000ce790, 0x0)
	/Users/alexander.emelin/centrifugal/rueidis/mux.go:173 +0x47c
github.com/redis/rueidis.(*mux).pipe(...)
	/Users/alexander.emelin/centrifugal/rueidis/mux.go:191
github.com/redis/rueidis.(*mux).Version(0x0?)
	/Users/alexander.emelin/centrifugal/rueidis/mux.go:205 +0x20
github.com/redis/rueidis.getClusterSlots({0x100c9a878, 0x140000ce790})
	/Users/alexander.emelin/centrifugal/rueidis/cluster.go:191 +0x4c
github.com/redis/rueidis.(*clusterClient)._refresh.func1({0x100c9a878?, 0x140000ce790?})
	/Users/alexander.emelin/centrifugal/rueidis/cluster.go:216 +0x34
created by github.com/redis/rueidis.(*clusterClient)._refresh in goroutine 34
	/Users/alexander.emelin/centrifugal/rueidis/cluster.go:215 +0x12c8

Could you please take a look?

@rueian
Copy link
Collaborator

rueian commented May 10, 2024

Hi @FZambia,

Wow, that's critical. Thank you so much for finding this. The fix will be merged soon.

@FZambia
Copy link
Contributor Author

FZambia commented May 10, 2024

Many thanks!

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

Successfully merging a pull request may close this issue.

2 participants