mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-19 03:16:58 +02:00
[client] Avoid deadlock when auto connect and early exit (#2528)
This commit is contained in:
@@ -61,9 +61,9 @@ func (c *ConnectClient) Run() error {
|
||||
// RunWithProbes runs the client's main logic with probes attached
|
||||
func (c *ConnectClient) RunWithProbes(
|
||||
probes *ProbeHolder,
|
||||
runningWg *sync.WaitGroup,
|
||||
runningChan chan error,
|
||||
) error {
|
||||
return c.run(MobileDependency{}, probes, runningWg)
|
||||
return c.run(MobileDependency{}, probes, runningChan)
|
||||
}
|
||||
|
||||
// RunOnAndroid with main logic on mobile system
|
||||
@@ -104,7 +104,7 @@ func (c *ConnectClient) RunOniOS(
|
||||
func (c *ConnectClient) run(
|
||||
mobileDependency MobileDependency,
|
||||
probes *ProbeHolder,
|
||||
runningWg *sync.WaitGroup,
|
||||
runningChan chan error,
|
||||
) error {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@@ -195,6 +195,7 @@ func (c *ConnectClient) run(
|
||||
log.Debug(err)
|
||||
if s, ok := gstatus.FromError(err); ok && (s.Code() == codes.PermissionDenied) {
|
||||
state.Set(StatusNeedsLogin)
|
||||
_ = c.Stop()
|
||||
return backoff.Permanent(wrapErr(err)) // unrecoverable error
|
||||
}
|
||||
return wrapErr(err)
|
||||
@@ -263,8 +264,9 @@ func (c *ConnectClient) run(
|
||||
log.Infof("Netbird engine started, the IP is: %s", peerConfig.GetAddress())
|
||||
state.Set(StatusConnected)
|
||||
|
||||
if runningWg != nil {
|
||||
runningWg.Done()
|
||||
if runningChan != nil {
|
||||
runningChan <- nil
|
||||
close(runningChan)
|
||||
}
|
||||
|
||||
<-engineCtx.Done()
|
||||
@@ -287,6 +289,7 @@ func (c *ConnectClient) run(
|
||||
log.Debugf("exiting client retry loop due to unrecoverable error: %s", err)
|
||||
if s, ok := gstatus.FromError(err); ok && (s.Code() == codes.PermissionDenied) {
|
||||
state.Set(StatusNeedsLogin)
|
||||
_ = c.Stop()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user