Retry resolving TCP address in agnhost/guestbook

Currently the guestbook application will fail if unable
to resolve TCP address on first attempt. If pod networking
is not setup when the application starts then it will be
unable to resolve, leading to frequent failures. This moves
the address resolution into the retry block so it will try
again if unsuccessful on first attempt.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
This commit is contained in:
hasheddan 2020-05-11 13:45:28 -05:00
parent 9b44fa4a07
commit 0cacc44fc9
No known key found for this signature in database
GPG Key ID: BD68BC686A14C271
3 changed files with 9 additions and 7 deletions

View File

@ -1 +1 @@
2.16
2.17

View File

@ -49,7 +49,7 @@ import (
)
func main() {
rootCmd := &cobra.Command{Use: "app", Version: "2.16"}
rootCmd := &cobra.Command{Use: "app", Version: "2.17"}
rootCmd.AddCommand(auditproxy.CmdAuditProxy)
rootCmd.AddCommand(connect.CmdConnect)

View File

@ -77,16 +77,18 @@ func registerNode(registerTo, port string) {
}
hostPort := net.JoinHostPort(registerTo, backendPort)
_, err := net.ResolveTCPAddr("tcp", hostPort)
if err != nil {
log.Fatalf("--slaveof param and/or --backend-port param are invalid. %v", err)
return
}
request := fmt.Sprintf("register?host=%s", getIP(hostPort).String())
log.Printf("Registering to master: %s/%s", hostPort, request)
start := time.Now()
for time.Since(start) < timeout {
_, err := net.ResolveTCPAddr("tcp", hostPort)
if err != nil {
log.Printf("--slaveof param and/or --backend-port param are invalid. %v. Retrying in 1 second.", err)
time.Sleep(sleep)
continue
}
response, err := dialHTTP(request, hostPort)
if err != nil {
log.Printf("encountered error while registering to master: %v. Retrying in 1 second.", err)