[GODRIVER-1025] "fail fast" client option Created: 07/May/19  Updated: 10/May/19  Resolved: 09/May/19

Status: Closed
Project: Go Driver
Component/s: Connections
Affects Version/s: 1.0.1
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Pierre Durand Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux
MongoDB 4.0



 Description   

Hello

I'm migrating my code from globalsign/mgo to the official mongo driver.

In my tests, I was using the "FailFast" optionĀ https://godoc.org/github.com/globalsign/mgo#DialInfo.FailFast

It allows to connect to a MongoDB server with a "normal" timeout (e.g. 10 sec), however it will return an error after the first failed attempt.

This is very useful in tests, because I want to skip my test if my local instance of MongoDB is not available.

With mgo, all my tests were skipped very quickly, because the connection attempt returned an error immediately, and wasn't retried.

However, in the mongo official driver, there is no such option. I can only define a very low "connect timeout" (e.g. 100 ms). This solution is not ideal, because on some busy CI server it could take longer to connect to MongoDB. This will cause "flaky" tests.



 Comments   
Comment by Pierre Durand [ 10/May/19 ]

OK, thank you.

Comment by Jeffrey Yemin [ 09/May/19 ]

Hi pierrre,

The Go driver follows the cross-driver server selection specification, which only defines a server selection timeout. Currently we have no plans to implement anything that's not part of that specification.

As a workaround, you could try calling the Client.Ping method using a Context with a short timeout to accomplish your goal.

Generated at Thu Feb 08 08:35:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.