[SERVER-41248] Ensure ReplicaSetMonitor initializes its random state with truly random data Created: 20/May/19  Updated: 29/Oct/23  Resolved: 19/Aug/19

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: 3.6.12, 4.0.9
Fix Version/s: 3.6.14, 4.0.13

Type: Bug Priority: Major - P3
Reporter: Mira Carey Assignee: Benjamin Caimano (Inactive)
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.0, v3.6
Sprint: Service Arch 2019-07-15, Service Arch 2019-08-12, Service Arch 2019-08-26
Participants:

 Description   

The replica set monitor in older versions of the server initializes it's random state via:

replica_set_monitor.cpp:1010

SetState::SetState(...) :
    ...
    rand(int64_t(time(0))),
    ...

which has the unfortunate side effect of being strongly synchronized with the system clock. This can cause non-random patterns of access across a mongos / series of mongos' in cases where all of the nodes are restarted at the same time and work is distributed evenly across the various mongos'.

Switching to use a real source of randomness for seeding the prngs in each set state should improve the real randomness of later server selection


Note: It appears this was fixed in 4.2 as part of unrelated code changes



 Comments   
Comment by Githook User [ 15/Aug/19 ]

Author:

{'username': 'shailejajain', 'email': 'shaileja.jain@gmail.com', 'name': 'Shaileja Jain'}

Message: SERVER-41248 Ensure ReplicaSetMonitor initializes its random state with truly random data

(cherry picked from commit ee71321881cfa25c0eba4948a71a9a6f6e5076a8)
Branch: v4.0
https://github.com/mongodb/mongo/commit/21c694fda7114932d73795f89ff52b25f8ec09c6

Comment by Shaileja Jain (Inactive) [ 09/Aug/19 ]

4.0 is in code freeze.

Comment by Githook User [ 09/Aug/19 ]

Author:

{'name': 'Shaileja Jain', 'username': 'shailejajain', 'email': 'shaileja.jain@gmail.com'}

Message: SERVER-41248 Ensure ReplicaSetMonitor initializes its random state with truly random data
Branch: v3.6
https://github.com/mongodb/mongo/commit/ee71321881cfa25c0eba4948a71a9a6f6e5076a8

Generated at Thu Feb 08 04:57:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.