Skip to content

Commit

Permalink
Revert "fix(telegram): reset backoff on connection ready"
Browse files Browse the repository at this point in the history
This reverts commit 23e26dc.
  • Loading branch information
ernado committed Oct 9, 2024
1 parent 242bf87 commit 244876a
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions telegram/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 244876a

Please sign in to comment.