mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-25 05:49:06 +01:00
IsRunning V0
This commit is contained in:
@@ -465,6 +465,15 @@ func parseRelayInfo(loginResp *mgmProto.LoginResponse) ([]string, *hmac.Token) {
|
|||||||
return relayCfg.GetUrls(), token
|
return relayCfg.GetUrls(), token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsRunning reports whether a client run is currently in flight. It is the
|
||||||
|
// single source of truth for "is the client running", owned by the supervisor.
|
||||||
|
func (c *ConnectClient) IsRunning() bool {
|
||||||
|
if c == nil || c.sup == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return c.sup.running.Load()
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ConnectClient) Engine() *Engine {
|
func (c *ConnectClient) Engine() *Engine {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package internal
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/internal/profilemanager"
|
"github.com/netbirdio/netbird/client/internal/profilemanager"
|
||||||
)
|
)
|
||||||
@@ -59,6 +60,10 @@ type supervisor struct {
|
|||||||
// runCancel cancels that run.
|
// runCancel cancels that run.
|
||||||
curExecOp *lifecycleCmd
|
curExecOp *lifecycleCmd
|
||||||
runCancel context.CancelFunc
|
runCancel context.CancelFunc
|
||||||
|
|
||||||
|
// running mirrors "a run is in flight" for lock-free reads from outside the
|
||||||
|
// loop goroutine (the single source of truth for "is the client running").
|
||||||
|
running atomic.Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSupervisor(ctx context.Context, run runFunc) *supervisor {
|
func newSupervisor(ctx context.Context, run runFunc) *supervisor {
|
||||||
@@ -101,6 +106,7 @@ func (s *supervisor) handleStart(cmd lifecycleCmd) {
|
|||||||
runCtx, cancel := context.WithCancel(s.ctx)
|
runCtx, cancel := context.WithCancel(s.ctx)
|
||||||
s.runCancel = cancel
|
s.runCancel = cancel
|
||||||
s.curExecOp = &cmd
|
s.curExecOp = &cmd
|
||||||
|
s.running.Store(true)
|
||||||
|
|
||||||
go func(ctx context.Context, cfg *profilemanager.Config, m MobileDependency, rc chan struct{}, lp string) {
|
go func(ctx context.Context, cfg *profilemanager.Config, m MobileDependency, rc chan struct{}, lp string) {
|
||||||
err := s.run(ctx, cfg, m, rc, lp)
|
err := s.run(ctx, cfg, m, rc, lp)
|
||||||
@@ -127,6 +133,7 @@ func (s *supervisor) handleStop(cmd lifecycleCmd) {
|
|||||||
// error back to whoever asked to be notified of the start.
|
// error back to whoever asked to be notified of the start.
|
||||||
func (s *supervisor) finishRun(err error) {
|
func (s *supervisor) finishRun(err error) {
|
||||||
s.runCancel = nil
|
s.runCancel = nil
|
||||||
|
s.running.Store(false)
|
||||||
if s.curExecOp != nil {
|
if s.curExecOp != nil {
|
||||||
notify(s.curExecOp.done, err)
|
notify(s.curExecOp.done, err)
|
||||||
s.curExecOp = nil
|
s.curExecOp = nil
|
||||||
|
|||||||
Reference in New Issue
Block a user