Fix error handling in openConnVia function (#2560)

This commit is contained in:
Zoltan Papp 2024-09-09 18:12:32 +02:00 committed by GitHub
parent 28248ea9f4
commit c720d54de6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)