diff --git a/telegram/connect.go b/telegram/connect.go index a4d484f567..f93ebbaf22 100644 --- a/telegram/connect.go +++ b/telegram/connect.go @@ -61,36 +61,23 @@ func (c *Client) reconnectUntilClosed(ctx context.Context) error { // Note that we currently have no timeout on connection, so this is // potentially eternal. b := tdsync.SyncBackoff(backoff.WithContext(c.connBackoff(), ctx)) - g := tdsync.NewCancellableGroup(ctx) - g.Go(func(ctx context.Context) error { - select { - case <-ctx.Done(): - return ctx.Err() - case <-c.ready.Ready(): - // Reset backoff on successful connection. - b.Reset() - return nil - } - }) - g.Go(func(ctx context.Context) error { - return backoff.RetryNotify(func() error { - if err := c.runUntilRestart(ctx); err != nil { - if c.isPermanentError(err) { - return backoff.Permanent(err) - } - return err + + return backoff.RetryNotify(func() error { + if err := c.runUntilRestart(ctx); err != nil { + if c.isPermanentError(err) { + return backoff.Permanent(err) } + return err + } - return nil - }, b, func(err error, timeout time.Duration) { - c.log.Info("Restarting connection", zap.Error(err), zap.Duration("backoff", timeout)) + return nil + }, b, func(err error, timeout time.Duration) { + c.log.Info("Restarting connection", zap.Error(err), zap.Duration("backoff", timeout)) - c.connMux.Lock() - c.conn = c.createPrimaryConn(nil) - c.connMux.Unlock() - }) + c.connMux.Lock() + c.conn = c.createPrimaryConn(nil) + c.connMux.Unlock() }) - return g.Wait() } func (c *Client) onReady() {