Skip to content

Commit

Permalink
fix: sync pool race condition (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
sysulq committed Apr 29, 2024
1 parent d00d2cc commit a3d5a0b
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions internal/tracker/seen.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ type SeenTracker struct {
currentIdx int
}

var pool sync.Pool
var pool = sync.Pool{
New: func() interface{} {
return &SeenTracker{}
},
}

func (s *SeenTracker) reset() {
// Always contains a root element at index 0.
Expand Down Expand Up @@ -331,12 +335,6 @@ func (s *SeenTracker) checkArray(node *unstable.Node) (first bool, err error) {
}

func (s *SeenTracker) checkInlineTable(node *unstable.Node) (first bool, err error) {
if pool.New == nil {
pool.New = func() interface{} {
return &SeenTracker{}
}
}

s = pool.Get().(*SeenTracker)
s.reset()

Expand Down

0 comments on commit a3d5a0b

Please sign in to comment.