[CDRIVER-4781] Using socketTimeoutMS=-1 results in an error Created: 10/Nov/23  Updated: 04/Dec/23  Resolved: 13/Nov/23

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: 1.24.0, 1.25.0
Fix Version/s: 1.26.0, 1.25.2

Type: Bug Priority: Unknown
Reporter: Kevin Albertson Assignee: Ezra Chung
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-4599 MSVC and MinGW compilation warnings i... Closed

 Description   

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”.



 Comments   
Comment by Githook User [ 15/Nov/23 ]

Author:

{'name': 'Kevin Albertson', 'email': 'kevin.albertson@mongodb.com', 'username': 'kevinAlbs'}

Message: CDRIVER-4781 add `void*` cast in test (#1476)
Branch: r1.25
https://github.com/mongodb/mongo-c-driver/commit/9f05e377f01be6728a1313aa74f9b53e2e1de7b8

Comment by Githook User [ 15/Nov/23 ]

Author:

{'name': 'Kevin Albertson', 'email': 'kevin.albertson@mongodb.com', 'username': 'kevinAlbs'}

Message: CDRIVER-4781 add `void*` cast in test (#1476)
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/3e6d56eceb3985e09aeb603deaffbf5029eeb543

Comment by Githook User [ 14/Nov/23 ]

Author:

{'name': 'Ezra Chung', 'email': '88335979+eramongodb@users.noreply.github.com', 'username': 'eramongodb'}

Message: CDRIVER-4781 Avoid intermediate uint32_t for socketTimeoutMS (#1475)

  • Fix format specifier in timeout range validation error messages
  • CDRIVER-4781 Avoid overflow of -1 sockettimeout in cast to intermediate uint32_t
  • Add regression test for negative sockettimeoutms validation
  • Update documentation with warnings for non-positive timeout values
  • Update timeout variables for type consistency
Comment by Githook User [ 13/Nov/23 ]

Author:

{'name': 'Ezra Chung', 'email': '88335979+eramongodb@users.noreply.github.com', 'username': 'eramongodb'}

Message: CDRIVER-4781 Avoid intermediate uint32_t for socketTimeoutMS (#1475)

  • Fix format specifier in timeout range validation error messages
  • CDRIVER-4781 Avoid overflow of -1 sockettimeout in cast to intermediate uint32_t
  • Add regression test for negative sockettimeoutms validation
  • Update documentation with warnings for non-positive timeout values
  • Update timeout variables for type consistency
Generated at Wed Feb 07 21:21:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.