From 1f952ce405a8af41384690dded1ee0bc13e5e7d3 Mon Sep 17 00:00:00 2001 From: Adnan Abdulhussein Date: Thu, 25 Oct 2018 18:23:08 +0200 Subject: [PATCH] update datastore module for mongodb connection timeout fix (#552) Signed-off-by: Adnan Abdulhussein --- Gopkg.lock | 4 ++-- vendor/github.com/kubeapps/common/datastore/datastore.go | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index a0fdfc20c..cf4fa72b4 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -135,7 +135,7 @@ [[projects]] branch = "master" - digest = "1:31857ddd6853f21e3b88195d2238f56c787bc19753033527ed841f68dc40e61a" + digest = "1:f15cda2356071e51ea44c35e3ca522d3db3f6b539a1bf8eab686095f985416fe" name = "github.com/kubeapps/common" packages = [ "datastore", @@ -143,7 +143,7 @@ "response", ] pruneopts = "UT" - revision = "707d33bc9333441366785395d93f1d9bcc196d64" + revision = "24f6ea203bc21cc1bb3352fbdca9d319dd34b8b0" [[projects]] digest = "1:ff5ebae34cfbf047d505ee150de27e60570e8c394b3b8fdbb720ff6ac71985fc" diff --git a/vendor/github.com/kubeapps/common/datastore/datastore.go b/vendor/github.com/kubeapps/common/datastore/datastore.go index 523ac9841..68ac9addd 100644 --- a/vendor/github.com/kubeapps/common/datastore/datastore.go +++ b/vendor/github.com/kubeapps/common/datastore/datastore.go @@ -19,16 +19,20 @@ package datastore import ( "errors" + "time" "gopkg.in/mgo.v2" ) +const defaultTimeout = 30 * time.Second + // Config configures the database connection type Config struct { URL string Database string Username string Password string + Timeout time.Duration } // Session is an interface for a MongoDB session @@ -133,6 +137,10 @@ func NewSession(conf Config) (Session, error) { if conf.Password != "" { dialInfo.Password = conf.Password } + if conf.Timeout == 0 { + conf.Timeout = defaultTimeout + } + dialInfo.Timeout = conf.Timeout session, err := mgo.DialWithInfo(dialInfo) if err != nil { return nil, errors.New("unable to connect to MongoDB")