Wire the stop-for-any-reason to the sup stop (and remove race on engine!)

This commit is contained in:
riccardom
2026-06-16 18:31:46 +02:00
parent 8b76b3d824
commit 4152c41796
+9 -16
View File
@@ -973,27 +973,20 @@ func (s *Server) cleanupConnection() error {
// path, so its clientRunning stays true. // path, so its clientRunning stays true.
s.clientRunning = false s.clientRunning = false
// Capture the engine reference before cancelling the context. // Tear the client down through the lifecycle supervisor BEFORE cancelling
// After actCancel(), the connectWithRetryRuns goroutine wakes up // the retry context. Stop serializes on the supervisor queue and blocks
// and sets connectClient.engine = nil, causing connectClient.Stop() // until the in-flight run has fully unwound (a clean, synchronous teardown).
// to skip the engine shutdown entirely. // It must run before actCancel: cancelling the context first would make
var engine *internal.Engine // Stop observe a dead context and return early without waiting.
if s.connectClient != nil { if s.connectClient != nil {
engine = s.connectClient.Engine() if err := s.connectClient.Stop(); err != nil {
}
s.actCancel()
if s.connectClient == nil {
return nil
}
if engine != nil {
if err := engine.Stop(); err != nil {
return err return err
} }
} }
// Stop the retry goroutine so it does not start a fresh run.
s.actCancel()
s.connectClient = nil s.connectClient = nil
s.isSessionActive.Store(false) s.isSessionActive.Store(false)