From 8b76b3d8241e209d206462331a4f99165c90ba03 Mon Sep 17 00:00:00 2001 From: riccardom Date: Tue, 16 Jun 2026 16:05:07 +0200 Subject: [PATCH] Keep the command DON'T DO COPIES!!! --- client/internal/connect_lifecycle.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/client/internal/connect_lifecycle.go b/client/internal/connect_lifecycle.go index 78bff5b92..4ad010253 100644 --- a/client/internal/connect_lifecycle.go +++ b/client/internal/connect_lifecycle.go @@ -42,7 +42,7 @@ type runFunc func(ctx context.Context, mobileDep MobileDependency, runningChan c // supervisor serializes start/stop of a single client run. Every request goes // through cmdCh and is handled one at a time by the loop goroutine, so two // lifecycle operations can never overlap and their order is preserved (FIFO). -// The loop goroutine is the sole owner of runCancel/runWaiter, so that state +// The loop goroutine is the sole owner of curExecOp/runCancel, so that state // needs no locking. The loop exits when the parent context is cancelled. type supervisor struct { ctx context.Context @@ -50,10 +50,11 @@ type supervisor struct { cmdCh chan lifecycleCmd runEnded chan runEndResult - // owned exclusively by the loop goroutine. A non-nil runCancel means a run - // is in flight; runWaiter is whoever asked to be notified when it ends. + // owned exclusively by the loop goroutine. curExecOp is the in-flight start + // command (nil = idle); its done channel is notified when the run ends. + // runCancel cancels that run. + curExecOp *lifecycleCmd runCancel context.CancelFunc - runWaiter chan error } func newSupervisor(ctx context.Context, run runFunc) *supervisor { @@ -88,14 +89,14 @@ func (s *supervisor) loop() { } func (s *supervisor) handleStart(cmd lifecycleCmd) { - if s.runCancel != nil { + if s.curExecOp != nil { notify(cmd.done, errAlreadyRunning) return } runCtx, cancel := context.WithCancel(s.ctx) s.runCancel = cancel - s.runWaiter = cmd.done + s.curExecOp = &cmd go func(ctx context.Context, m MobileDependency, rc chan struct{}, lp string) { err := s.run(ctx, m, rc, lp) @@ -104,7 +105,7 @@ func (s *supervisor) handleStart(cmd lifecycleCmd) { } func (s *supervisor) handleStop(cmd lifecycleCmd) { - if s.runCancel == nil { + if s.curExecOp == nil { notify(cmd.done, nil) return } @@ -122,9 +123,9 @@ func (s *supervisor) handleStop(cmd lifecycleCmd) { // error back to whoever asked to be notified of the start. func (s *supervisor) finishRun(err error) { s.runCancel = nil - if s.runWaiter != nil { - notify(s.runWaiter, err) - s.runWaiter = nil + if s.curExecOp != nil { + notify(s.curExecOp.done, err) + s.curExecOp = nil } }