@@ -35,13 +35,18 @@ func NewClient(address string, config ClientConfig, baseLogger zerolog.Logger) C
3535
3636// Dial attempts to connect with the client
3737func (client * Client ) Dial () (net.Conn , error ) {
38- client .currentRetries = 0
3938
4039 var err error
4140 var conn net.Conn
4241 client .logger .Info ().Msg ("dialing" )
43- for ; client .config .MaxConnectionRetries <= 0 || client .currentRetries < client .config .MaxConnectionRetries ; client .currentRetries ++ {
42+ for client .config .MaxConnectionRetries <= 0 || client .currentRetries < client .config .MaxConnectionRetries {
43+ client .currentRetries ++
4444 conn , err = client .config .DialContext (client .config .Context , "tcp" , client .address )
45+
46+ backoffDuration := client .config .ConnectionBackoffFunction (client .currentRetries )
47+ client .logger .Error ().Stack ().Err (err ).Dur ("backoff" , backoffDuration ).Int ("retries" , client .currentRetries + 1 ).Msg ("retrying" )
48+ time .Sleep (backoffDuration )
49+
4550 if err == nil {
4651 client .logger .Info ().Msg ("connected" )
4752 return conn , nil
@@ -55,10 +60,6 @@ func (client *Client) Dial() (net.Conn, error) {
5560 client .logger .Error ().Stack ().Err (err ).Msg ("failed" )
5661 return nil , err
5762 }
58-
59- backoffDuration := client .config .ConnectionBackoffFunction (client .currentRetries )
60- client .logger .Debug ().Stack ().Err (err ).Dur ("backoff" , backoffDuration ).Int ("retries" , client .currentRetries + 1 ).Msg ("retrying" )
61- time .Sleep (backoffDuration )
6263 }
6364
6465 client .logger .Debug ().Int ("max" , client .config .MaxConnectionRetries ).Msg ("max connection retries exceeded" )
0 commit comments