Guard is done inside not from external. Stop called unconditionally

This commit is contained in:
riccardom
2026-06-16 23:18:50 +02:00
parent 8d46580c13
commit 91d2d341b7
+6 -8
View File
@@ -417,14 +417,12 @@ func (c *ConnectClient) run(runCtx context.Context, config *profilemanager.Confi
c.engine = nil c.engine = nil
c.engineMutex.Unlock() c.engineMutex.Unlock()
// todo: consider to remove this condition. Is not thread safe. // Always tear the engine down once its context is cancelled. engine.Stop
// We should always call Stop(), but we need to verify that it is idempotent // is nil-guarded per component, so calling it unconditionally is safe and
if engine.wgInterface != nil { // avoids both the data race on engine.wgInterface and skipping teardown
log.Infof("ensuring %s is removed, Netbird engine context cancelled", engine.wgInterface.Name()) // when the interface was never brought up (e.g. a mid-start failure).
if err := engine.Stop(); err != nil {
if err := engine.Stop(); err != nil { log.Errorf("Failed to stop engine: %v", err)
log.Errorf("Failed to stop engine: %v", err)
}
} }
c.statusRecorder.ClientTeardown() c.statusRecorder.ClientTeardown()