Skip to content

Commit

Permalink
More code review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Dec 3, 2014
1 parent 22e2963 commit 732c7fa
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,13 @@ func (c *Client) stayConnected() {
func (c *Client) connect() *connInfo {
log.Trace("Connecting ...")
var lastErr error
consecutiveFailures := 0
for {
for consecutiveFailures := 0; consecutiveFailures <= c.ReconnectAttempts; consecutiveFailures++ {
if c.isClosed() {
log.Tracef("Connection closed, stop trying to connect")
return &connInfo{
err: closedError,
}
}
if consecutiveFailures > c.ReconnectAttempts {
log.Tracef("Done trying to connect: %s", lastErr)
return &connInfo{
err: fmt.Errorf("Unable to connect: %s", lastErr),
}
}
delay := time.Duration(consecutiveFailures) * reconnectDelayInterval
if delay > maxReconnectDelay {
delay = maxReconnectDelay
Expand All @@ -69,8 +62,11 @@ func (c *Client) connect() *connInfo {
log.Tracef("Unable to connect: %s", err)
lastErr = err
info = nil
consecutiveFailures += 1
}

err := fmt.Errorf("Unable to connect within %d tries: %s", c.ReconnectAttempts+1, lastErr)
log.Trace(err)
return &connInfo{err: err}
}

func (c *Client) connectOnce() (*connInfo, error) {
Expand Down

0 comments on commit 732c7fa

Please sign in to comment.