From c720d54de692f141a7d3a2ab6ef9f0fa6b3196ce Mon Sep 17 00:00:00 2001 From: Zoltan Papp Date: Mon, 9 Sep 2024 18:12:32 +0200 Subject: [PATCH] Fix error handling in openConnVia function (#2560) --- relay/client/manager.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/relay/client/manager.go b/relay/client/manager.go index 3e152a963..a9d294160 100644 --- a/relay/client/manager.go +++ b/relay/client/manager.go @@ -29,6 +29,7 @@ var ( type RelayTrack struct { sync.RWMutex relayClient *Client + err error } func NewRelayTrack() *RelayTrack { @@ -235,6 +236,9 @@ func (m *Manager) openConnVia(serverAddress, peerKey string) (net.Conn, error) { rt.RLock() m.relayClientsMutex.RUnlock() defer rt.RUnlock() + if rt.err != nil { + return nil, rt.err + } return rt.relayClient.OpenConn(peerKey) } m.relayClientsMutex.RUnlock() @@ -247,6 +251,9 @@ func (m *Manager) openConnVia(serverAddress, peerKey string) (net.Conn, error) { rt.RLock() m.relayClientsMutex.Unlock() defer rt.RUnlock() + if rt.err != nil { + return nil, rt.err + } return rt.relayClient.OpenConn(peerKey) } @@ -259,6 +266,7 @@ func (m *Manager) openConnVia(serverAddress, peerKey string) (net.Conn, error) { relayClient := NewClient(m.ctx, serverAddress, m.tokenStore, m.peerID) err := relayClient.Connect() if err != nil { + rt.err = err rt.Unlock() m.relayClientsMutex.Lock() delete(m.relayClients, serverAddress)