Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
fleetd: protect access to global Server instance
Browse files Browse the repository at this point in the history
There are three different paths in the main fleetd goroutine that can
access the global `srv` Server - reconfigurations, shutdowns and
statedumps. Right now there's nothing preventing racy access to this
instance, so introduce a mutex to protect it.

One potential issue with this is that it means that a reconfigure or
state dump can "block" a shutdown, but IMHO if this occurs it will
expose behaviour that is broken and needs to be fixed anyway.
  • Loading branch information
jonboulle committed Dec 17, 2014
1 parent 12801e9 commit f303763
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions fleetd/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"os/signal"
"strings"
"sync"
"syscall"

"github.com/coreos/fleet/Godeps/_workspace/src/github.com/rakyll/globalconf"
Expand Down Expand Up @@ -85,7 +86,11 @@ func main() {
}
srv.Run()

srvMutex := sync.Mutex{}

reconfigure := func() {
srvMutex.Lock()
defer srvMutex.Unlock()
log.Infof("Reloading configuration from %s", *cfgPath)

cfg, err := getConfig(cfgset, *cfgPath)
Expand All @@ -105,12 +110,16 @@ func main() {

shutdown := func() {
log.Infof("Gracefully shutting down")
srvMutex.Lock()
defer srvMutex.Unlock()
srv.Stop()
srv.Purge()
os.Exit(0)
}

writeState := func() {
srvMutex.Lock()
defer srvMutex.Unlock()
log.Infof("Dumping server state")

encoded, err := json.Marshal(srv)
Expand Down

0 comments on commit f303763

Please sign in to comment.