From 410caa61413f8c09e92b34ff7dfc30f9e25756c2 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Tue, 4 Mar 2014 18:39:43 +0400 Subject: [PATCH] Fix race in shutdown: context should be shut down in case of error. --- cmd/context.go | 12 +++++++++--- main.go | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/context.go b/cmd/context.go index 50f65502..ff5f2923 100644 --- a/cmd/context.go +++ b/cmd/context.go @@ -139,7 +139,13 @@ func ShutdownContext() { context.fileMemProfile = nil } } - context.database.Close() - context.downloader.Shutdown() - context.progress.Shutdown() + if context.database != nil { + context.database.Close() + } + if context.downloader != nil { + context.downloader.Shutdown() + } + if context.progress != nil { + context.progress.Shutdown() + } } diff --git a/main.go b/main.go index 20f34856..7615b3cf 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,7 @@ func loadConfig(command *commander.Command) error { } if !os.IsNotExist(err) { fatal(fmt.Errorf("error loading config file %s: %s", configLocation, err)) + return nil } } @@ -67,6 +68,9 @@ func main() { fatal(err) return } + if returnCode != 0 { + return + } err = cmd.InitContext(command) if err != nil {