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

fix: random nil dereference caused by non-zero PipelineMultiplex #427

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (m *mux) SetOnCloseHook(fn func(error)) {
}

func (m *mux) setCloseHookOnWire(i uint16, w wire) {
if w != m.dead {
if w != m.dead && w != m.init {
w.SetOnCloseHook(func(err error) {
if err != ErrClosing {
if m.wire[i].CompareAndSwap(w, m.init) {
Expand Down
41 changes: 24 additions & 17 deletions redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,9 @@ func TestSingleClientIntegration(t *testing.T) {
}
defer ShouldNotLeaked(SetupLeakDetection())
client, err := NewClient(ClientOption{
InitAddress: []string{"127.0.0.1:6379"},
ConnWriteTimeout: 180 * time.Second,
InitAddress: []string{"127.0.0.1:6379"},
ConnWriteTimeout: 180 * time.Second,
PipelineMultiplex: 1,
})
if err != nil {
t.Fatal(err)
Expand All @@ -814,7 +815,8 @@ func TestSentinelClientIntegration(t *testing.T) {
Sentinel: SentinelOption{
MasterSet: "test",
},
SelectDB: 2, // https://github.com/redis/rueidis/issues/138
SelectDB: 2, // https://github.com/redis/rueidis/issues/138
PipelineMultiplex: 1,
})
if err != nil {
t.Fatal(err)
Expand All @@ -832,10 +834,11 @@ func TestClusterClientIntegration(t *testing.T) {
}
defer ShouldNotLeaked(SetupLeakDetection())
client, err := NewClient(ClientOption{
InitAddress: []string{"127.0.0.1:7001", "127.0.0.1:7002", "127.0.0.1:7003"},
ConnWriteTimeout: 180 * time.Second,
ShuffleInit: true,
Dialer: net.Dialer{KeepAlive: -1},
InitAddress: []string{"127.0.0.1:7001", "127.0.0.1:7002", "127.0.0.1:7003"},
ConnWriteTimeout: 180 * time.Second,
ShuffleInit: true,
Dialer: net.Dialer{KeepAlive: -1},
PipelineMultiplex: 1,
})
if err != nil {
t.Fatal(err)
Expand All @@ -851,9 +854,10 @@ func TestSingleClient5Integration(t *testing.T) {
}
defer ShouldNotLeaked(SetupLeakDetection())
client, err := NewClient(ClientOption{
InitAddress: []string{"127.0.0.1:6355"},
ConnWriteTimeout: 180 * time.Second,
DisableCache: true,
InitAddress: []string{"127.0.0.1:6355"},
ConnWriteTimeout: 180 * time.Second,
DisableCache: true,
PipelineMultiplex: 1,
})
if err != nil {
t.Fatal(err)
Expand All @@ -870,11 +874,12 @@ func TestCluster5ClientIntegration(t *testing.T) {
}
defer ShouldNotLeaked(SetupLeakDetection())
client, err := NewClient(ClientOption{
InitAddress: []string{"127.0.0.1:7004", "127.0.0.1:7005", "127.0.0.1:7006"},
ConnWriteTimeout: 180 * time.Second,
ShuffleInit: true,
DisableCache: true,
Dialer: net.Dialer{KeepAlive: -1},
InitAddress: []string{"127.0.0.1:7004", "127.0.0.1:7005", "127.0.0.1:7006"},
ConnWriteTimeout: 180 * time.Second,
ShuffleInit: true,
DisableCache: true,
Dialer: net.Dialer{KeepAlive: -1},
PipelineMultiplex: 1,
})
if err != nil {
t.Fatal(err)
Expand All @@ -896,6 +901,7 @@ func TestSentinel5ClientIntegration(t *testing.T) {
Sentinel: SentinelOption{
MasterSet: "test5",
},
PipelineMultiplex: 1,
})
if err != nil {
t.Fatal(err)
Expand All @@ -912,8 +918,9 @@ func TestKeyDBSingleClientIntegration(t *testing.T) {
}
defer ShouldNotLeaked(SetupLeakDetection())
client, err := NewClient(ClientOption{
InitAddress: []string{"127.0.0.1:6344"},
ConnWriteTimeout: 180 * time.Second,
InitAddress: []string{"127.0.0.1:6344"},
ConnWriteTimeout: 180 * time.Second,
PipelineMultiplex: 1,
})
if err != nil {
t.Fatal(err)
Expand Down