From ed5647028a2d676cdc4f5a7adcd603f8d4b6f29a Mon Sep 17 00:00:00 2001 From: Zoltan Papp Date: Fri, 28 Mar 2025 18:08:26 +0100 Subject: [PATCH] [client] Prevent calling the onDisconnected callback in incorrect state (#3582) Prevent calling the onDisconnected callback if the ICE connection has never been established If call onDisconnected without onConnected then overwrite the relayed status in the conn priority variable. --- client/internal/peer/conn.go | 1 + client/internal/peer/worker_ice.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/client/internal/peer/conn.go b/client/internal/peer/conn.go index 92723d606..baf1a2db4 100644 --- a/client/internal/peer/conn.go +++ b/client/internal/peer/conn.go @@ -502,6 +502,7 @@ func (conn *Conn) onRelayDisconnected() { if err := conn.removeWgPeer(); err != nil { conn.log.Errorf("failed to remove wg endpoint: %v", err) } + conn.currentConnPriority = connPriorityNone } if conn.wgProxyRelay != nil { diff --git a/client/internal/peer/worker_ice.go b/client/internal/peer/worker_ice.go index 5ceb3f453..4ff13b455 100644 --- a/client/internal/peer/worker_ice.go +++ b/client/internal/peer/worker_ice.go @@ -65,6 +65,7 @@ func NewWorkerICE(ctx context.Context, log *log.Entry, config ConnConfig, conn * iFaceDiscover: ifaceDiscover, statusRecorder: statusRecorder, hasRelayOnLocally: hasRelayOnLocally, + lastKnownState: ice.ConnectionStateDisconnected, } localUfrag, localPwd, err := icemaker.GenerateICECredentials() @@ -213,7 +214,7 @@ func (w *WorkerICE) reCreateAgent(agentCancel context.CancelFunc, candidates []i w.lastKnownState = ice.ConnectionStateConnected return case ice.ConnectionStateFailed, ice.ConnectionStateDisconnected: - if w.lastKnownState != ice.ConnectionStateDisconnected { + if w.lastKnownState == ice.ConnectionStateConnected { w.lastKnownState = ice.ConnectionStateDisconnected w.conn.onICEStateDisconnected() }