diff --git a/Makefile b/Makefile index 141a378eb6..d8fbe60842 100644 --- a/Makefile +++ b/Makefile @@ -157,12 +157,17 @@ buildsrc: $(SRCPATH)/crypto/lib/libsodium.a node_exporter NONGO_BIN deps $(ALGOD cd $(SRCPATH) && \ go vet $(UNIT_TEST_SOURCES) $(E2E_TEST_SOURCES) +SOURCES_RACE := github.com/algorand/go-algorand/cmd/kmd + ## Build binaries with the race detector enabled in them. ## This allows us to run e2e tests with race detection. +## We overwrite bin-race/kmd with a non -race version due to +## the incredible performance impact of -race on Scrypt. build-race: build @mkdir -p $(GOPATH)/bin-race cd $(SRCPATH) && \ - GOBIN=$(GOPATH)/bin-race go install $(GOTAGS) -ldflags="$(GOLDFLAGS)" $(SOURCES) + GOBIN=$(GOPATH)/bin-race go install $(GOTAGS) -race -ldflags="$(GOLDFLAGS)" $(SOURCES) && \ + GOBIN=$(GOPATH)/bin-race go install $(GOTAGS) -ldflags="$(GOLDFLAGS)" $(SOURCES_RACE) NONGO_BIN_FILES=$(GOPATH)/bin/find-nodes.sh $(GOPATH)/bin/update.sh $(GOPATH)/bin/updatekey.json $(GOPATH)/bin/COPYING diff --git a/daemon/kmd/server/server.go b/daemon/kmd/server/server.go index cd4d9b9662..e3298fea1e 100644 --- a/daemon/kmd/server/server.go +++ b/daemon/kmd/server/server.go @@ -101,15 +101,13 @@ func ValidateConfig(cfg WalletServerConfig) error { // MakeWalletServer takes a WalletServerConfig, and returns a validated, // configured WalletServer. -func MakeWalletServer(config WalletServerConfig) (WalletServer, error) { - var ws WalletServer - +func MakeWalletServer(config WalletServerConfig) (*WalletServer, error) { err := ValidateConfig(config) if err != nil { - return ws, err + return nil, err } - ws = WalletServer{ + ws := &WalletServer{ WalletServerConfig: config, netPath: filepath.Join(config.DataDir, NetFilename), pidPath: filepath.Join(config.DataDir, PIDFilename), @@ -144,7 +142,7 @@ func (ws *WalletServer) releaseFileLock() error { } // Write out a file containing the address kmd is listening on -func (ws WalletServer) writeStateFiles(netAddr string) (err error) { +func (ws *WalletServer) writeStateFiles(netAddr string) (err error) { // netPath file contains path to sock file err = ioutil.WriteFile(ws.netPath, []byte(netAddr), 0640) if err != nil { @@ -156,7 +154,7 @@ func (ws WalletServer) writeStateFiles(netAddr string) (err error) { } // Delete the state files generated by writeStateFiles -func (ws WalletServer) deleteStateFiles() { +func (ws *WalletServer) deleteStateFiles() { os.Remove(ws.pidPath) os.Remove(ws.netPath) } @@ -164,7 +162,7 @@ func (ws WalletServer) deleteStateFiles() { // makeWatchdogCallback generates a callback function that either 1. does // nothing if ws.Timeout is nil, or 2. kicks a watchdog timer that will kill // kmd when it expires. -func (ws WalletServer) makeWatchdogCallback(kill chan os.Signal) func() { +func (ws *WalletServer) makeWatchdogCallback(kill chan os.Signal) func() { // If Timeout is nil, then we will not kill kmd after a timeout if ws.Timeout == nil { return func() {} @@ -193,7 +191,7 @@ func (ws WalletServer) makeWatchdogCallback(kill chan os.Signal) func() { // returns an error if it was unable to start the server. It reads from the // `kill` channel in order to shut down the server gracefully, and returns a // `died` channel that will be written after the server exits. -func (ws WalletServer) Start(kill chan os.Signal) (died chan error, sock string, err error) { +func (ws *WalletServer) Start(kill chan os.Signal) (died chan error, sock string, err error) { // Ensure we're the only instance of kmd running in this data directory err = ws.acquireFileLock() if err != nil { diff --git a/test/framework/fixtures/libgoalFixture.go b/test/framework/fixtures/libgoalFixture.go index 0b29c7e922..200216f0dc 100644 --- a/test/framework/fixtures/libgoalFixture.go +++ b/test/framework/fixtures/libgoalFixture.go @@ -278,6 +278,14 @@ func (f *LibGoalFixture) ShutdownImpl(preserveData bool) { } } +// intercept baseFixture.failOnError so we can clean up any algods that are still alive +func (f *LibGoalFixture) failOnError(err error, message string) { + if err != nil { + f.network.Stop(f.binDir) + f.baseFixture.failOnError(err, message) + } +} + // PrimaryDataDir returns the data directory for the PrimaryNode for the network func (f *LibGoalFixture) PrimaryDataDir() string { return f.network.PrimaryDataDir()