[CDRIVER-3730] Do not interpret URI option values of 0 as unset Created: 30/Jun/20  Updated: 21/Aug/23

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

Type: Bug Priority: Major - P3
Reporter: Kevin Albertson Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: rp-toSched
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CDRIVER-3721 Define behavior of connectTimeoutMS=0... Backlog
Related
is related to CDRIVER-2056 mongoc_uri_get_option_as_int32() does... Closed
is related to CDRIVER-3167 URI Spec conformance Backlog
Quarter: FY24Q3

 Description   

While working on CDRIVER-3721, I discovered libmongoc interprets connecttimeoutms=0 to mean the option is unset and actually defaults to 10000. So there is no current way to set an unlimited connection timeout. This contradicts the URI options spec, but libmongoc's source comment above mongoc_uri_get_option_as_int32 indicates it's intentional.

 *       Checks if the URI 'option' is set and of correct type (int32).
 *       The special value '0' is considered as "unset".
 *       This is so users can provide
 *       sprintf("mongodb://localhost/?option=%d", myvalue) style connection

This has happened for other options as well, and required separate getters.

CDRIVER-2056 introduced mongoc_uri_get_local_threshold_option to return 0 if specified.

CDRIVER-1933 introduce the internal _mongoc_uri_get_max_staleness_option to return 0 if specified.

Including connecttimeoutms, these are the other integer options obtained (in non-test code) using the mongoc_uri_get_option_as_int* helpers:

  • connecttimeoutms
  • socketcheckintervalms
  • waitqueuetimeoutms
  • sockettimeoutms
  • socketcheckintervalms.
  • zlibcompressionlevel
  • heartbeatfrequencyms
  • serverselectiontimeoutms
  • wtimeoutms

Cross referencing with the URI options spec, 0 can be meaningful for this subset of options:

  • sockettimeoutms. 0 should mean "no timeout".
  • connecttimeoutms. 0 should mean "no timeout".
  • zlibcompressionlevel. 0 should mean to be no compression.
  • wtimeoutms. 0 should mean no timeout. This is ok, since the default is also 0.

In my opinion, libmongoc should always consider an explicit 0 value as being set to 0, not as unset. It would be a backwards breaking behavior change, but libmongoc already breaks the rationale given in mongoc_uri_get_option_as_int32 for maxstalenessseconds and localthresholdms. A URI with those options set to 0 is considered to have them set:

mongodb://localhost/?maxStalenessSeconds=0&localThresholdMS=0


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