[CXX-1197] Client and pool initialization should fail if no instance configured Created: 20/Jan/17 Updated: 31/Mar/22 |
|
| Status: | Backlog |
| Project: | C++ Driver |
| Component/s: | Implementation |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | J Rassi | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
Programs that use mongocxx functionality without first creating a mongocxx::instance object are ill-formed. We should attempt to detect this scenario, fail fast, and provide readable error messages to users, where possible. One approach to address this is to have the mongocxx::client and mongocxx::pool constructors fail if no instance is configured. This will cover many ill-formed programs, but not all. |
| Comments |
| Comment by J Rassi [ 08/May/17 ] |
|
See http://stackoverflow.com/questions/43761382/cant-connect-to-mongodb-from-the-c-code for an additional manifestation of failing to configure an instance. This user encountered the error "Failed to resolve '127.0.0.1'" when attempting to perform a write. |
| Comment by J Rassi [ 20/Jan/17 ] |
|
I think this is somewhat of a different case of "ensuring some objects exists for the duration of the use of another" that deserves special attention, where I'm seeing significant user pain and I think we can address it with minimal additional logic. I'd love to see us at least add some simple assertions to mongocxx::client and mongocxx::pool for 3.2, to help these users out before we release 4.0 (edit: though I do like your idea of making instance a client/pool factory for 4.0!). Currently, it's too easy for users to copy-paste code from elsewhere that issues database operations, and in the process fail to copy-paste the code that creates the mongocxx::instance object. The symptoms of failing to create a mongocxx::instance are really non-obvious: the driver reports itself to the server as the C driver (since libmongoc::handshake_data_append("mongocxx", ...) is never called), and select driver functionality fails strangely due to mongoc_init() never being called. While it's true that users can accidentally use collection objects after destroying the database object that owns them, it's much more difficult to accidentally create a collection object without ever creating a database object in the first place. However, per above, it's easy to accidentally create a client object without ever creating an instance object. Because of this, I think users would appreciate us adding some basic sanity checks to client and pool. |
| Comment by David Golden [ 20/Jan/17 ] |
|
There are numerous places in the driver where users are responsible for ensuring some objects exists for the duration of the use of another. I see this as a conceptually similar case and we can address it with better documentation. I'd definitely prefer not to make an instance pointer required. I'd be more open to considering for a 4.0 release making instance into a client/pool factory and eliminating the public constructor for client/pool. |
| Comment by J Rassi [ 20/Jan/17 ] |
|
Alternatively, we could make a pointer to an instance object a required parameter for mongocxx::client and mongocxx::pool. |