From 66b116ecb2fddd08d256f2db4e6453e7d836a832 Mon Sep 17 00:00:00 2001 From: Aaron Greenberg
Date: Fri, 10 Nov 2017 16:38:02 -0500 Subject: [PATCH] Use a linear backoff when connecting to DB Closes #159 --- cmd/clair/main.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/clair/main.go b/cmd/clair/main.go index 23d33a48..b6fa1c4e 100644 --- a/cmd/clair/main.go +++ b/cmd/clair/main.go @@ -132,10 +132,22 @@ func Boot(config *Config) { st := stopper.NewStopper() // Open database - db, err := database.Open(config.Database) - if err != nil { - log.Fatal(err) + var db database.Datastore + var dbError error + maxConnectionAttempts := 20 + for attempts := 1; attempts <= maxConnectionAttempts; attempts++ { + db, dbError = database.Open(config.Database) + if dbError == nil { + break + } + log.Error(dbError); + time.Sleep(time.Duration(attempts) * time.Second) } + + if dbError != nil { + log.Fatal(dbError) + } + defer db.Close() // Start notifier