Fix blocking Close

This commit is contained in:
Zoltán Papp
2025-02-27 12:39:40 +01:00
parent 4f668fdf5f
commit aa3cd20214
+5 -2
View File
@@ -3,6 +3,7 @@ package internal
import ( import (
"context" "context"
"os" "os"
"sync"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@@ -28,6 +29,7 @@ type ConnMgr struct {
excludes map[string]struct{} excludes map[string]struct{}
wg sync.WaitGroup
ctxCancel context.CancelFunc ctxCancel context.CancelFunc
} }
@@ -54,6 +56,7 @@ func (e *ConnMgr) Start(parentCtx context.Context) {
e.ctxCancel = cancel e.ctxCancel = cancel
e.lazyConnMgr.Start(ctx) e.lazyConnMgr.Start(ctx)
e.wg.Add(1)
go e.receiveLazyConnEvents(ctx) go e.receiveLazyConnEvents(ctx)
} }
@@ -126,13 +129,13 @@ func (e *ConnMgr) Close() {
return return
} }
e.ctxCancel() e.ctxCancel()
// todo wait for receiveLazyConnEvents to finish
e.lazyConnMgr.Close() e.lazyConnMgr.Close()
e.wg.Wait()
e.lazyConnMgr = nil e.lazyConnMgr = nil
} }
func (e *ConnMgr) receiveLazyConnEvents(ctx context.Context) { func (e *ConnMgr) receiveLazyConnEvents(ctx context.Context) {
defer e.wg.Done()
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():