[CDRIVER-557] failed client creation doesn't result in Null returned Created: 04/Mar/15  Updated: 03/May/17  Resolved: 04/Mar/15

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: 1.0.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Mark Stevens Assignee: Unassigned
Resolution: Done Votes: 0
Labels: Bug, Client, Connection
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7, visual studio 2010 express,



 Description   

Utilising the mongoc driver, ive discovered that when you create a connection, using
client = mongoc_client_new(connection_string);

The returned value when the mongodb isnt running is not a null value. This means any tests/checks carried out do not catch that the server hasnt been connected to, causing issues further down the line.

Looking in the source I can't see anything that would set a value Null, either in v1.0.2, not v1.1.0 that was recently released.



 Comments   
Comment by Hannes Magnusson [ 04/Mar/15 ]

This is intentional.
All MongoDB drivers use "lazy connections" – we don't actually create the first connection to MongoDB until we actually have something to send to MongoDB.

This is done for HA reasons; You should always be able to create a mongoc_client_t instance – even when the server is down.
By the time you actually execute something, we may have found a server that is available.

You should be checking the results of all over-the-wire operations anyway, as they could fail at any time, so lazy connections actually reduce the amount of error checking you need to do in your code since you don't need to handle failing to create mongoc_client

Generated at Wed Feb 07 21:09:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.