[GODRIVER-503] mongo.Connect is always succeeding even the db is not up Created: 18/Jul/18 Updated: 27/Oct/23 Resolved: 31/Aug/18 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | Connections, Error Handling |
| Affects Version/s: | 0.0.7 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | jeyanthi | Assignee: | Kristofer Brandow (Inactive) |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
My golang connection code
Output while mongodb is local is up
while mongodb in local is down
|
| Comments |
| Comment by Kristofer Brandow (Inactive) [ 20/Jul/18 ] | ||||
|
Hi jeyanthi, If you want to know if mongo.Client.Connect has found an actual server, you send a single ping command. The commands themselves will timeout if a suitable server cannot be found. You don't have to do a ping at all, but if the driver can't find a mongo deployment all of the commands you run will have a server selection timeout. --Kris | ||||
| Comment by jeyanthi [ 20/Jul/18 ] | ||||
|
@kris Brandow Thanks for the reply But in that case , before running every command I need to test ping isn't it ? instead of one stop for connection. instead you can return some kind of context from connect to make sure database is up and running, and that would do trick isn't it ? | ||||
| Comment by Kristofer Brandow (Inactive) [ 20/Jul/18 ] | ||||
|
Hi jeyanthi, The mongo.Client.Connect method doesn't ensure a database has been connected to before returning, it just starts background monitoring threads that will attempt to discover a mongo deployment. If you want to know if a *mongo.Client has successfully connected to a server, you can run a ping command (via mongo.Database.RunCommand) with a context.Context with a low timeout. We will be adding a Ping method to the mongo.Client type, and you can track that via Let me know if you have any other questions and thanks for opening a ticket for this! --Kris | ||||
| Comment by jeyanthi [ 18/Jul/18 ] | ||||
|
This is even happening with the latest version
|