From cb77ff466163988d2a994a5ac3e4bd0f5fe13cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Wed, 10 Jul 2024 22:33:15 +0200 Subject: [PATCH] Fix relay instance address indication --- relay/client/client.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/relay/client/client.go b/relay/client/client.go index 630f49708..8358c21f7 100644 --- a/relay/client/client.go +++ b/relay/client/client.go @@ -111,6 +111,7 @@ type Client struct { readLoopMutex sync.Mutex wgReadLoop sync.WaitGroup instanceURL string + muInstanceURL sync.Mutex onDisconnectListener func() listenerMutex sync.Mutex @@ -190,8 +191,8 @@ func (c *Client) OpenConn(dstPeerID string) (net.Conn, error) { // ServerInstanceURL returns the address of the relay server. It could change after the close and reopen the connection. func (c *Client) ServerInstanceURL() (string, error) { - c.mu.Lock() - defer c.mu.Unlock() + c.muInstanceURL.Lock() + defer c.muInstanceURL.Unlock() if c.instanceURL == "" { return "", fmt.Errorf("relay connection is not established") } @@ -272,7 +273,9 @@ func (c *Client) handShake() error { if err != nil { return err } + c.muInstanceURL.Lock() c.instanceURL = ia + c.muInstanceURL.Unlock() return nil } @@ -310,6 +313,11 @@ func (c *Client) readLoop(relayConn net.Conn) { } hc.Stop() + + c.muInstanceURL.Lock() + c.instanceURL = "" + c.muInstanceURL.Unlock() + c.notifyDisconnected() c.wgReadLoop.Done() _ = c.close(false)