fix: close sessions before connections on shutdown

This commit is contained in:
zarazaex69
2026-05-16 04:13:07 +03:00
parent 6222896921
commit ff90942214
3 changed files with 12 additions and 9 deletions
+6 -6
View File
@@ -388,15 +388,15 @@ func (c *Client) handleReconnect(ctx context.Context, cfg Config, cancel context
if oldControlStop != nil {
oldControlStop()
}
if oldControl != nil {
_ = oldControl.Close()
}
if oldSess != nil {
_ = oldSess.Close()
}
if oldConn != nil {
_ = oldConn.Close()
}
if oldControl != nil {
_ = oldControl.Close()
}
// Server-side may still be tearing down its own session when our callback
// fires — carriers don't guarantee reconnect callbacks are delivered to both
@@ -587,6 +587,9 @@ func (c *Client) shutdown() {
if controlStop != nil {
controlStop()
}
if sess != nil {
_ = sess.Close()
}
if conn != nil {
_ = conn.Close()
}
@@ -596,9 +599,6 @@ func (c *Client) shutdown() {
if control != nil {
_ = control.Close()
}
if sess != nil {
_ = sess.Close()
}
}
func setupCipher(keyHex string) (*crypto.Cipher, error) {
+3 -3
View File
@@ -415,12 +415,12 @@ func (s *Server) closeSession() {
if controlStop != nil {
controlStop()
}
if conn != nil {
_ = conn.Close()
}
if sess != nil {
_ = sess.Close()
}
if conn != nil {
_ = conn.Close()
}
if oldSID != "" {
s.onClose(oldSID, "closed")
}
+3
View File
@@ -98,6 +98,9 @@ func Run(ctx context.Context, cfg Config, run Runner) error {
if err := runCycle(ctx, cfg, run, state, cycle, &lastErr); err != nil {
return err
}
if ctx.Err() != nil {
return nil //nolint:nilerr // context cancellation is normal supervisor shutdown
}
}
}