From 32dcd2a6bdb62d6a0927da5825e994402bc9d899 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Thu, 28 Nov 2024 13:22:27 +0300 Subject: [PATCH] fix(telegram): handle auth errors on reconnect Fix #1458 --- telegram/connect.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/telegram/connect.go b/telegram/connect.go index 73b7065f45..9c7e3d7053 100644 --- a/telegram/connect.go +++ b/telegram/connect.go @@ -12,6 +12,7 @@ import ( "github.com/gotd/td/exchange" "github.com/gotd/td/tdsync" "github.com/gotd/td/telegram/auth" + "github.com/gotd/td/tgerr" ) func (c *Client) runUntilRestart(ctx context.Context) error { @@ -54,7 +55,17 @@ func (c *Client) runUntilRestart(ctx context.Context) error { } func (c *Client) isPermanentError(err error) bool { - return errors.Is(err, exchange.ErrKeyFingerprintNotFound) + // See https://github.com/gotd/td/issues/1458. + if errors.Is(err, exchange.ErrKeyFingerprintNotFound) { + return true + } + if tgerr.Is(err, "AUTH_KEY_UNREGISTERED") || tgerr.Is(err, "SESSION_EXPIRED") { + return true + } + if auth.IsUnauthorized(err) { + return true + } + return false } func (c *Client) reconnectUntilClosed(ctx context.Context) error {