Skip to content

Commit

Permalink
Fix incorrect timeout calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
perk11 committed Jul 24, 2024
1 parent 9dafc62 commit e120fc6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,13 @@ func connectToService(config ServiceConfig) net.Conn {
}

func connectWithWaiting(serviceHost string, servicePort string, serviceName string, timeout time.Duration) net.Conn {
deadline := time.Now().Add(timeout * time.Second)
deadline := time.Now().Add(timeout)
for time.Now().Before(deadline) {
conn, err := net.DialTimeout("tcp", net.JoinHostPort(serviceHost, servicePort), time.Second)
if err == nil {
return conn
}
//log.Printf("[%s] Error when connecting to %s:%s, trying again in 100ms %v", serviceName, serviceHost, servicePort, err)
time.Sleep(time.Millisecond * 100)
}
log.Printf("[%s] Error: failed to connect to %s:%s: All connection attempts failed after trying for %s", serviceName, serviceHost, servicePort, timeout)
Expand Down

0 comments on commit e120fc6

Please sign in to comment.