Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Wait for shutdown before returning from main()
Browse files Browse the repository at this point in the history
This is more idiomatic Go and less likely to lead to subtle bugs.
  • Loading branch information
bboreham committed Mar 4, 2019
1 parent 8c82f10 commit f0ab7f1
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions cmd/fluxd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,6 @@ func main() {
errc <- fmt.Errorf("%s", <-c)
}()

// This means we can return, and it will use the shutdown
// protocol.
defer func() {
// wait here until stopping.
logger.Log("exiting", <-errc)
close(shutdown)
shutdownWg.Wait()
}()

// Cluster component.
var clusterVersion string
var sshKeyRing ssh.KeyRing
Expand Down Expand Up @@ -546,5 +537,8 @@ func main() {
}()
}

// Fall off the end, into the waiting procedure.
// wait here until stopping.
logger.Log("exiting", <-errc)
close(shutdown)
shutdownWg.Wait()
}

0 comments on commit f0ab7f1

Please sign in to comment.