Skip to content

Commit

Permalink
[release-19.0] Fix a potential connection pool leak. (vitessio#17807) (
Browse files Browse the repository at this point in the history
…vitessio#17812)

Signed-off-by: Arthur Schreiber <arthurschreiber@github.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
  • Loading branch information
vitess-bot[bot] authored Feb 17, 2025
1 parent 3040c48 commit 747296f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions go/pools/smartconnpool/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
26 changes: 26 additions & 0 deletions go/pools/smartconnpool/stack_test.go
Original file line number Diff line number Diff line change
@@ -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())
}

0 comments on commit 747296f

Please sign in to comment.