[CDRIVER-4251] mongoc_client_new_from_uri may leak topology Created: 23/Dec/21  Updated: 28/Oct/23  Resolved: 04/Jan/22

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

Type: Bug Priority: Minor - P4
Reporter: Jeremy Mikola Assignee: Jeremy Mikola
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CDRIVER-3723 Validate URI options on client/client... Closed

 Description   

In mongoc_client_new, the topology is freed before returning NULL. The same does not happen in mongoc_client_new_from_uri.

This can be addressed alongside CDRIVER-3723, since that ticket will refactor both methods alongside introduction of a new mongoc_client_new_from_uri_with_error method.



 Comments   
Comment by Githook User [ 04/Jan/22 ]

Author:

{'name': 'Jeremy Mikola', 'email': 'jmikola@gmail.com', 'username': 'jmikola'}

Message: CDRIVER-3723 finalize URI during client/pool construction (#921)

Introduces new mongoc_client_new_from_uri_with_error and mongoc_client_pool_new_with_error methods. Also addresses topology leak in mongoc_client_new_from_uri (CDRIVER-4251).

  • Remove redundant warnings about unused results
  • Explain why we need not handle null result from _mongoc_client_new_from_topology
  • Log URI errors in mongoc_client_new as warnings
  • Clear logs between /Client/max_staleness assertions
  • Set error instead of logging in mongoc_client_pool_new_with_error
  • Remove test expecting a client with an invalid topology
  • Revise assertions in /loadbalanced/client_uri_validation test

This no longer requires constructing a client and expecting an error through server selection.

  • Use tracing macro for return statement
  • Check MONGOC_ENABLE_SSL in mongoc_client_new_from_uri_with_error

Moving the check up from _mongoc_client_new_from_topology makes mongoc_client_new_from_uri_with_error consistent with mongoc_client_pool_new_with_error. Additionally, we add log message assertions to corresponding tests.

  • Anticipate null pool or client in SRV error tests
  • Remove obsolete tests for invalid LB topologies

These tests were previously introduced in CDRIVER-4184 but no longer apply now that we prohibit construction of clients and pools with an invalid topology.

  • _mongoc_client_new_from_topology should require a valid topology
  • Document precondition for _mongoc_client_new_from_topology

Co-authored-by: Ezra Chung <88335979+eramongodb@users.noreply.github.com>
Co-authored-by: Kevin Albertson <kevin.albertson@mongodb.com>
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/e7e15002d63cb57424f467c5f21eafa9ec0f018e

Comment by Jeremy Mikola [ 23/Dec/21 ]

https://github.com/mongodb/mongo-c-driver/pull/921

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