diff --git a/internal/mtproto/options.go b/internal/mtproto/options.go index 70c66ff68b..5b98bc9af4 100644 --- a/internal/mtproto/options.go +++ b/internal/mtproto/options.go @@ -131,10 +131,10 @@ func (opt *Options) setDefaults() { opt.SaltFetchInterval = 1 * time.Hour } if opt.PingTimeout == 0 { - opt.PingTimeout = 10 * time.Second + opt.PingTimeout = 15 * time.Second } if opt.PingInterval == 0 { - opt.PingInterval = 15 * time.Second + opt.PingInterval = 1 * time.Minute } if opt.RequestTimeout == nil { opt.RequestTimeout = func(req uint32) time.Duration { diff --git a/telegram/connect.go b/telegram/connect.go index f045f2718a..8f7d0f0918 100644 --- a/telegram/connect.go +++ b/telegram/connect.go @@ -22,8 +22,7 @@ func (c *Client) runUntilRestart(ctx context.Context) error { if !c.noUpdatesMode { g.Go(func(ctx context.Context) error { // Call method which requires authorization, to subscribe for updates. - // See https://core.telegram.org/api/updates#subscribing-to-updates - c.log.Debug("Calling c.Self to subscribe for updates") + // See https://core.telegram.org/api/updates#subscribing-to-updates. self, err := c.Self(ctx) if err != nil { // Ignore unauthorized errors. @@ -59,29 +58,21 @@ func (c *Client) isPermanentError(err error) bool { } 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)) return backoff.RetryNotify(func() error { if err := c.runUntilRestart(ctx); err != nil { - if ctxErr := ctx.Err(); ctxErr != nil { - c.log.Error("Stopping reconnection attempts due to parent context error", - zap.Error(err), - zap.Errors("error_parent", []error{ctxErr}), - ) - return errors.Wrap(err, "parent context closed") - } if c.isPermanentError(err) { return backoff.Permanent(err) } - return errors.Wrap(err, "runUntilRestart") + return err } return nil }, b, func(err error, timeout time.Duration) { - c.log.Info("Restarting connection", - zap.Error(err), - zap.Duration("backoff", timeout), - ) + c.log.Info("Restarting connection", zap.Error(err), zap.Duration("backoff", timeout)) c.connMux.Lock() c.conn = c.createPrimaryConn(nil) diff --git a/telegram/internal/manager/conn.go b/telegram/internal/manager/conn.go index bc81705aa9..0532d5df62 100644 --- a/telegram/internal/manager/conn.go +++ b/telegram/internal/manager/conn.go @@ -123,12 +123,10 @@ func (c *Conn) Run(ctx context.Context) (err error) { defer func() { if err != nil && ctx.Err() == nil { c.log.Debug("Connection dead", zap.Error(err)) - } else { - c.log.Debug("Connection closed") } }() return c.proto.Run(ctx, func(ctx context.Context) error { - // Signal death on init error. Otherwise, connection shutdown + // Signal death on init error. Otherwise connection shutdown // deadlocks in OnSession that occurs before init fails. err := c.init(ctx) if err != nil { diff --git a/telegram/options.go b/telegram/options.go index 7b0dd95c9f..6d6d121b08 100644 --- a/telegram/options.go +++ b/telegram/options.go @@ -153,9 +153,7 @@ func defaultBackoff(c clock.Clock) func() backoff.BackOff { return func() backoff.BackOff { b := backoff.NewExponentialBackOff() b.Clock = c - b.MaxElapsedTime = time.Minute - b.InitialInterval = time.Millisecond * 100 - b.MaxInterval = time.Second + b.MaxElapsedTime = 0 return b } }