diff --git a/go/pools/smartconnpool/stack.go b/go/pools/smartconnpool/stack.go index ea7ae50201e..ba38e31cecf 100644 --- a/go/pools/smartconnpool/stack.go +++ b/go/pools/smartconnpool/stack.go @@ -48,6 +48,7 @@ func (s *connStack[C]) Pop() (*Pooled[C], bool) { newHead := oldHead.next.Load() if s.top.CompareAndSwap(oldHead, popCount, newHead, popCount+1) { + oldHead.next.Store(nil) return oldHead, true } runtime.Gosched() diff --git a/go/pools/smartconnpool/stack_test.go b/go/pools/smartconnpool/stack_test.go new file mode 100644 index 00000000000..a8150bd8186 --- /dev/null +++ b/go/pools/smartconnpool/stack_test.go @@ -0,0 +1,26 @@ +package smartconnpool + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +type testPooled struct { + Connection +} + +func TestStackPop(t *testing.T) { + s := &connStack[testPooled]{} + + first := &Pooled[testPooled]{} + s.Push(first) + + second := &Pooled[testPooled]{} + s.Push(second) + + c, ok := s.Pop() + assert.True(t, ok) + + assert.Nil(t, c.next.Load()) +}