Summary
Setting the URI option socketTimeoutMS=-1 results in an error in C driver 1.25.1 with the message: "timeout_msec value 4294967295 exceeds supported 32-bit range"
Here is a test showing the issue:
// Regression test for CDRIVER-4781. static void test_timeout_msec_exceeds (void) { bson_error_t error; mongoc_uri_t *uri = test_framework_get_uri (); mongoc_uri_set_option_as_int32 (uri, MONGOC_URI_SOCKETTIMEOUTMS, -1); mongoc_client_t *client = mongoc_client_new_from_uri_with_error (uri, &error); ASSERT_OR_PRINT (client, error); test_framework_set_ssl_opts (client); bson_t *ping = BCON_NEW ("ping", BCON_INT32 (1)); bool ok = mongoc_client_command_simple (client, "db", ping, NULL, NULL, &error); // On commit abb0bb7da8230d342dac5061623c1e4936ed46d9, results in error: // "timeout_msec value 4294967295 exceeds supported 32-bit range" // On prior commit 3e8a24311c21917420fd7fd2b00637deb4b168ce, results in // success. ASSERT_OR_PRINT (ok, error); bson_destroy (ping); mongoc_client_destroy (client); mongoc_uri_destroy (uri); }
In versions <1.24.0, it was not an error. The error check was added in CDRIVER-4599.
4294967295 is the result of casting -1 as a uint32_t. mongoc_cluster_t::sockettimeoutms is represented as a uint32_t.
Proposal: support the value -1 (and possibly negative values) for backwards compatibility. Document use of negative values as deprecated.
Background & Motivation
This impacted a customer setting connectTimeoutMS to -1. Refer: https://mongodb.slack.com/archives/C0V2T72R2/p1699631179298719
Open questions
1. In versions <1.24.0 was -1 interpreted as "no timeout" or "use default timeout"?
2. Is 0 considered "no timeout" in the C driver? The URI spec specifies:
non-negative integer; 0 means no timeout
But the 1.25.1 C driver documentation claims "0" means "apply the default":
Setting any of the *timeoutMS options above to 0 will be interpreted as “use the default value”.
- is related to
-
CDRIVER-4599 MSVC and MinGW compilation warnings in libmongoc, examples, and tests
- Closed
- related to
-
CDRIVER-5815 Socket timeout cannot be disabled
- Backlog