1
0
mirror of https://github.com/redis/go-redis.git synced 2025-11-04 02:33:24 +03:00

fix(pool): Pool ReAuth should not interfere with handoff (#3547)

* fix(pool): wip, pool reauth should not interfere with handoff

* fix credListeners map

* fix race in tests

* better conn usable timeout

* add design decision comment

* few small improvements

* update marked as queued

* add Used to clarify the state of the conn

* rename test

* fix(test): fix flaky test

* lock inside the listeners collection

* address pr comments

* Update internal/auth/cred_listeners.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update internal/pool/buffer_size_test.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* wip refactor entraid

* fix maintnotif pool hook

* fix mocks

* fix nil listener

* sync and async reauth based on conn lifecycle

* be able to reject connection OnGet

* pass hooks so the tests can observe reauth

* give some time for the background to execute commands

* fix tests

* only async reauth

* Update internal/pool/pool.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update internal/auth/streaming/pool_hook.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update internal/pool/conn.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore(redisotel): use metric.WithAttributeSet to avoid copy (#3552)

In order to improve performance replace `WithAttributes` with `WithAttributeSet`.
This avoids the slice allocation and copy that is done in `WithAttributes`.

For more information see https://github.com/open-telemetry/opentelemetry-go/blob/v1.38.0/metric/instrument.go#L357-L376

* chore(docs): explain why MaxRetries is disabled for ClusterClient (#3551)

Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>

* exponential backoff

* address pr comments

* address pr comments

* remove rlock

* add some comments

* add comments

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Warnar Boekkooi <wboekkooi@impossiblecloud.com>
Co-authored-by: Justin <justindsouza80@gmail.com>
This commit is contained in:
Nedyalko Dyakov
2025-10-22 12:45:30 +03:00
committed by GitHub
parent 14a8814540
commit a15e76394c
23 changed files with 1138 additions and 143 deletions

View File

@@ -10,17 +10,19 @@ import (
// TestHook for testing hook functionality
type TestHook struct {
OnGetCalled int
OnPutCalled int
GetError error
PutError error
ShouldPool bool
ShouldRemove bool
OnGetCalled int
OnPutCalled int
OnRemoveCalled int
GetError error
PutError error
ShouldPool bool
ShouldRemove bool
ShouldAccept bool
}
func (th *TestHook) OnGet(ctx context.Context, conn *Conn, isNewConn bool) error {
func (th *TestHook) OnGet(ctx context.Context, conn *Conn, isNewConn bool) (bool, error) {
th.OnGetCalled++
return th.GetError
return th.ShouldAccept, th.GetError
}
func (th *TestHook) OnPut(ctx context.Context, conn *Conn) (shouldPool bool, shouldRemove bool, err error) {
@@ -28,6 +30,10 @@ func (th *TestHook) OnPut(ctx context.Context, conn *Conn) (shouldPool bool, sho
return th.ShouldPool, th.ShouldRemove, th.PutError
}
func (th *TestHook) OnRemove(ctx context.Context, conn *Conn, reason error) {
th.OnRemoveCalled++
}
func TestPoolHookManager(t *testing.T) {
manager := NewPoolHookManager()
@@ -37,8 +43,8 @@ func TestPoolHookManager(t *testing.T) {
}
// Add hooks
hook1 := &TestHook{ShouldPool: true}
hook2 := &TestHook{ShouldPool: true}
hook1 := &TestHook{ShouldPool: true, ShouldAccept: true}
hook2 := &TestHook{ShouldPool: true, ShouldAccept: true}
manager.AddHook(hook1)
manager.AddHook(hook2)
@@ -51,10 +57,13 @@ func TestPoolHookManager(t *testing.T) {
ctx := context.Background()
conn := &Conn{} // Mock connection
err := manager.ProcessOnGet(ctx, conn, false)
accept, err := manager.ProcessOnGet(ctx, conn, false)
if err != nil {
t.Errorf("ProcessOnGet should not error: %v", err)
}
if !accept {
t.Error("Expected accept to be true")
}
if hook1.OnGetCalled != 1 {
t.Errorf("Expected hook1.OnGetCalled to be 1, got %d", hook1.OnGetCalled)
@@ -99,11 +108,12 @@ func TestHookErrorHandling(t *testing.T) {
// Hook that returns error on Get
errorHook := &TestHook{
GetError: errors.New("test error"),
ShouldPool: true,
GetError: errors.New("test error"),
ShouldPool: true,
ShouldAccept: true,
}
normalHook := &TestHook{ShouldPool: true}
normalHook := &TestHook{ShouldPool: true, ShouldAccept: true}
manager.AddHook(errorHook)
manager.AddHook(normalHook)
@@ -112,10 +122,13 @@ func TestHookErrorHandling(t *testing.T) {
conn := &Conn{}
// Test that error stops processing
err := manager.ProcessOnGet(ctx, conn, false)
accept, err := manager.ProcessOnGet(ctx, conn, false)
if err == nil {
t.Error("Expected error from ProcessOnGet")
}
if accept {
t.Error("Expected accept to be false")
}
if errorHook.OnGetCalled != 1 {
t.Errorf("Expected errorHook.OnGetCalled to be 1, got %d", errorHook.OnGetCalled)
@@ -134,9 +147,10 @@ func TestHookShouldRemove(t *testing.T) {
removeHook := &TestHook{
ShouldPool: false,
ShouldRemove: true,
ShouldAccept: true,
}
normalHook := &TestHook{ShouldPool: true}
normalHook := &TestHook{ShouldPool: true, ShouldAccept: true}
manager.AddHook(removeHook)
manager.AddHook(normalHook)
@@ -170,7 +184,7 @@ func TestHookShouldRemove(t *testing.T) {
func TestPoolWithHooks(t *testing.T) {
// Create a pool with hooks
hookManager := NewPoolHookManager()
testHook := &TestHook{ShouldPool: true}
testHook := &TestHook{ShouldPool: true, ShouldAccept: true}
hookManager.AddHook(testHook)
opt := &Options{
@@ -197,7 +211,7 @@ func TestPoolWithHooks(t *testing.T) {
}
// Test adding hook to pool
additionalHook := &TestHook{ShouldPool: true}
additionalHook := &TestHook{ShouldPool: true, ShouldAccept: true}
pool.AddPoolHook(additionalHook)
if pool.hookManager.GetHookCount() != 2 {