[CDRIVER-2067] Server selection is not random on Windows Created: 22/Feb/17  Updated: 03/May/17  Resolved: 02/Mar/17

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.5.0
Fix Version/s: 1.7.0

Type: New Feature 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

Issue Links:
Related
related to CDRIVER-2068 mongocxx::pool mongos failover Closed
is related to CDRIVER-1639 Rand used to pick Mongo server is not... Closed

 Description   

In the process of fixing CDRIVER-1639 "Rand used to pick Mongo server is not seeded" I changed how the driver randomly chooses a suitable server when built with Microsoft Visual Studio. Before, it used the standard rand() function on every platform. After, it uses rand_s() in MSVC. I didn't realize that the return value of rand_s() is zero on success, rather than the random number.

We use its return value as the index into the list of suitable servers; therefore, we always choose the "first" suitable server, typically the first one in the seed list.



 Comments   
Comment by Githook User [ 02/Mar/17 ]

Author:

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

Message: CDRIVER-2067 fix rand num generator in MSVC
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/81d194541e65209f670fe8f9e3706c1750947be0

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