diff --git a/internal/vpn/client.go b/internal/vpn/client.go index c999ef78bb..a43ff62b00 100644 --- a/internal/vpn/client.go +++ b/internal/vpn/client.go @@ -187,18 +187,25 @@ func (c *Client) Serve() error { c.setAppStatus(ClientStatusConnecting) - for { - if err := c.dialServeConn(); err != nil { - fmt.Printf("dialServeConn: %v\n", err) - } - + r := netutil.NewDefaultRetrier(c.log) + err := r.Do(context.Background(), func() error { if c.isClosed() { return nil } - c.setAppStatus(ClientStatusReconnecting) - fmt.Println("Connection broke, reconnecting...") + if err := c.dialServeConn(); err != nil { + c.setAppStatus(ClientStatusReconnecting) + fmt.Println("Connection broke, reconnecting...") + return fmt.Errorf("dialServeConn: %w", err) + } + + return nil + }) + if err != nil { + return fmt.Errorf("failed to connect to the server: %w", err) } + + return nil } // Close closes client.