Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close connection before exiting #36

Merged
merged 1 commit into from
Feb 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ func buildCredentials(skipVerify bool, caCerts, clientCert, clientKey, serverNam
}

func main() {
retcode := 0
defer func() { os.Exit(retcode) }()

ctx, cancel := context.WithCancel(context.Background())

c := make(chan os.Signal, 1)
Expand All @@ -182,7 +185,8 @@ func main() {
creds, err := buildCredentials(flTLSNoVerify, flTLSCACert, flTLSClientCert, flTLSClientKey, flTLSServerName)
if err != nil {
log.Printf("failed to initialize tls credentials. error=%v", err)
os.Exit(StatusInvalidArguments)
retcode = StatusInvalidArguments
return
}
opts = append(opts, grpc.WithTransportCredentials(creds))
} else {
Expand All @@ -202,7 +206,8 @@ func main() {
} else {
log.Printf("error: failed to connect service at %q: %+v", flAddr, err)
}
os.Exit(StatusConnectionFailure)
retcode = StatusConnectionFailure
return
}
connDuration := time.Since(connStart)
defer conn.Close()
Expand All @@ -222,13 +227,15 @@ func main() {
} else {
log.Printf("error: health rpc failed: %+v", err)
}
os.Exit(StatusRPCFailure)
retcode = StatusRPCFailure
return
}
rpcDuration := time.Since(rpcStart)

if resp.GetStatus() != healthpb.HealthCheckResponse_SERVING {
log.Printf("service unhealthy (responded with %q)", resp.GetStatus().String())
os.Exit(StatusUnhealthy)
retcode = StatusUnhealthy
return
}
if flVerbose {
log.Printf("time elapsed: connect=%v rpc=%v", connDuration, rpcDuration)
Expand Down