Skip to content

Commit

Permalink
Prevent reconnect loops with short delay
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Feb 15, 2024
1 parent f69a5da commit f546cce
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion messagix/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func (c *Client) Connect() error {
go func() {
reconnectIn := 2 * time.Second
for {
connectStart := time.Now()
err := c.socket.Connect()
if ctx.Err() != nil {
return
Expand All @@ -271,7 +272,7 @@ func (c *Client) Connect() error {
return
}
c.eventHandler(&Event_SocketError{Err: err})
if errors.Is(err, ErrInReadLoop) {
if time.Since(connectStart) > 2*time.Minute {
reconnectIn = 2 * time.Second
} else {
reconnectIn *= 2
Expand Down

0 comments on commit f546cce

Please sign in to comment.