Skip to content

Commit

Permalink
Ping the mongo session when the connection is retrieved.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jefferai committed Dec 19, 2017
1 parent 6a74c11 commit 3ba108f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion plugins/database/mongodb/connection_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3ba108f

Please sign in to comment.