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

Commit

Permalink
Move "shutdown protocol" after other uses of 'defer'
Browse files Browse the repository at this point in the history
Currently, `memcachedClient.Stop()` is getting called on return from
`main()`, which breaks things if the cache moves address.
  • Loading branch information
bboreham committed Mar 4, 2019
1 parent 8c82f10 commit cf9102e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 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,15 @@ func main() {
}()
}

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

// Fall off the end, into the waiting procedure.
}

0 comments on commit cf9102e

Please sign in to comment.