diff --git a/client/internal/conn_mgr.go b/client/internal/conn_mgr.go index aae6153bc..486cad28b 100644 --- a/client/internal/conn_mgr.go +++ b/client/internal/conn_mgr.go @@ -27,6 +27,8 @@ type ConnMgr struct { peerStore *peerstore.Store excludes map[string]struct{} + + ctxCancel context.CancelFunc } func NewConnMgr(peerStore *peerstore.Store, iface lazyconn.WGIface) *ConnMgr { @@ -42,12 +44,15 @@ func NewConnMgr(peerStore *peerstore.Store, iface lazyconn.WGIface) *ConnMgr { return e } -func (e *ConnMgr) Start(ctx context.Context) { +func (e *ConnMgr) Start(parentCtx context.Context) { if e.lazyConnMgr == nil { log.Infof("lazy connection manager is disabled") return } + ctx, cancel := context.WithCancel(parentCtx) + e.ctxCancel = cancel + e.lazyConnMgr.Start(ctx) go e.receiveLazyConnEvents(ctx) } @@ -120,6 +125,8 @@ func (e *ConnMgr) Close() { if e.lazyConnMgr == nil { return } + e.ctxCancel() + // todo wait for receiveLazyConnEvents to finish e.lazyConnMgr.Close() e.lazyConnMgr = nil