Skip to content

Commit

Permalink
Fix a potential connection pool leak.
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schreiber <arthurschreiber@github.com>
  • Loading branch information
arthurschreiber committed Feb 17, 2025
1 parent 341c62c commit 9253b8c
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 9253b8c

Please sign in to comment.