hashicorp / go-set

The go-set package provides generic Set implementations for Go, including HashSet for types with a Hash() function and TreeSet for orderable data
Mozilla Public License 2.0
118 stars 8 forks source link

iterator method of treeSet has goroutine leaks #52

Closed zonewave closed 1 year ago

zonewave commented 1 year ago

I use "goleak" to detector leak:

    t.Run("diff set", func(t *testing.T) {
        defer goleak.VerifyNone(t)
        t1 := TreeSetFrom[int, Compare[int]]([]int{1, 2, 3}, Cmp[int])
        t2 := TreeSetFrom[int, Compare[int]]([]int{4, 5, 6}, Cmp[int])
        must.False(t, t1.Subset(t2))
    })

if not iter all node, the channel will block

image
shoenig commented 1 year ago

Good catch, I had been thinking about ways to iterate 2 trees (for the .Equal and .Subset cases) without the use of goroutines, but after so many years of programming in Go using goroutines is just easier.

If we could eliminate the use of goroutines though, that would be even better!