Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-3730

Do not interpret URI option values of 0 as unset

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None

      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
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: