fix mem leak in hubConnectionIndex (#22560)

Этот коммит содержится в:
byigorv
2023-03-24 08:52:37 +03:00
коммит произвёл GitHub
родитель 9b5afb1b5f
Коммит 017c51c246
2 изменённых файлов: 39 добавлений и 0 удалений

Просмотреть файл

@@ -8,6 +8,7 @@ import (
"net"
"net/http"
"net/http/httptest"
"runtime"
"testing"
"time"
@@ -539,6 +540,42 @@ func BenchmarkHubConnIndex(b *testing.B) {
})
}
func TestHubConnIndexRemoveMemLeak(t *testing.T) {
th := Setup(t)
defer th.TearDown()
connIndex := newHubConnectionIndex(1 * time.Second)
wc := &WebConn{
Platform: th.Service,
Suite: th.Suite,
}
wc.SetConnectionID(model.NewId())
wc.SetSession(&model.Session{})
ch := make(chan struct{})
runtime.SetFinalizer(wc, func(*WebConn) {
close(ch)
})
connIndex.Add(wc)
connIndex.Remove(wc)
runtime.GC()
timer := time.NewTimer(3 * time.Second)
defer timer.Stop()
select {
case <-ch:
case <-timer.C:
require.Fail(t, "timeout waiting for collection of wc")
}
assert.Len(t, connIndex.byConnection, 0)
}
var hubSink *Hub
func BenchmarkGetHubForUserId(b *testing.B) {