Ping the mongo session when the connection is retrieved.

This was in the deprecated backend where it fixed a similar issue a long
time ago but for some reason didn't make it over. Additionally the
function wasn't being locked properly.

Hopefully fixes #2973
This commit is contained in:
Jeff Mitchell 2017-12-19 10:11:04 -05:00
parent 6a74c119f3
commit 3ba108f51e

View File

@ -90,12 +90,18 @@ func (c *mongoDBConnectionProducer) Initialize(ctx context.Context, conf map[str
// Connection creates a database connection.
func (c *mongoDBConnectionProducer) Connection(_ context.Context) (interface{}, error) {
c.Lock()
defer c.Unlock()
if !c.Initialized {
return nil, connutil.ErrNotInitialized
}
if c.session != nil {
return c.session, nil
if err := c.session.Ping(); err == nil {
return c.session, nil
}
c.session.Close()
}
dialInfo, err := parseMongoURL(c.ConnectionURL)