Skip to content

Commit

Permalink
Revert "fix: try lowering the chance of hangup"
Browse files Browse the repository at this point in the history
This reverts commit f621c72.
  • Loading branch information
ernado committed Jan 30, 2024
1 parent 49ac6a9 commit ac7db6a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 22 deletions.
4 changes: 2 additions & 2 deletions internal/mtproto/options.go
Expand Up @@ -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 {
Expand Down
19 changes: 5 additions & 14 deletions telegram/connect.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions telegram/internal/manager/conn.go
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions telegram/options.go
Expand Up @@ -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
}
}

0 comments on commit ac7db6a

Please sign in to comment.