[CDRIVER-752] Server selection times out immediately on Solaris Created: 17/Jul/15  Updated: 25/Jul/16  Resolved: 21/Jul/15

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: 1.2.0
Fix Version/s: 1.2-beta0

Type: Bug Priority: Critical - P2
Reporter: A. Jesse Jiryu Davis Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Solaris 11, x86_64


Issue Links:
Related
is related to CDRIVER-1305 Some tests hang on 32-bit Unix Closed

 Description   

In 1.2.0-dev, mongoc_topology_select is responsible for selecting a server from your deployment for an operation. In pooled clients, if mongoc_topology_select doesn't know of a suitable server, it uses a condition variable to wait up to serverSelectionTimeoutMS for the monitor thread to discover one.

To use pthread_cond_wait, the driver begins by calculating the current time in milliseconds since the epoch:

   struct timeval tv;
   int64_t msec;
 
   bson_gettimeofday (&tv);
   msec = (tv.tv_sec * 1000) + (tv.tv_usec / 1000) + timeout_msec;

This works on platforms where tv_sec is a 64-bit int, but on Solaris it's 32 bits and overflows. (These days, representing tv_sec requires 31 bits, so multiplying it by 1000 overflows.)

The driver constructs a negative timespec from this calculation and passes it to pthread_cond_wait, which returns EINVAL and mongoc_topology_select quits.



 Comments   
Comment by A. Jesse Jiryu Davis [ 25/Jul/16 ]

Could be related to CDRIVER-1305.

Comment by A. Jesse Jiryu Davis [ 21/Jul/15 ]

No need for backport, mongoc_cond_timedwait is only in 1.2.

Comment by Githook User [ 21/Jul/15 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-752 int overflow in mongoc_cond_timedwait

On Solaris, at least, timeval.tv_sec is 32 bits. Cast to int64_t before
multiplying by 1000 to avoid overflow when converting from seconds to ms.
Branch: 1.2.0-dev
https://github.com/mongodb/mongo-c-driver/commit/73a3693685cb640fc40f42f3aeb66b95368be014

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