[GODRIVER-2223] Use "math/rand" instead of "crypto/rand" for UUID generator Created: 09/Nov/21  Updated: 28/Oct/23  Resolved: 12/Nov/21

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.8.0

Type: Improvement Priority: Major - P3
Reporter: Matt Dale Assignee: Matt Dale
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to GODRIVER-2349 Prevent session ID reuse due to lower... Closed
related to GODRIVER-2361 Investigate using "x/exp/rand" or "go... Closed

 Description   

The "x/mongo/driver/uuid package currently uses "crypto/rand" as its randomness source for generating UUIDs. The cryptographically secure randomness source on some systems can be extremely slow. Also, the driver sessions specification specifically suggests using a pseudo-random number generator.

See a CockroachDB discussion on "crypto/rand" performance for more context.

Definition of done:

  • "x/mongo/driver/uuid uses "math/rand" instead of "crypto/rand".
  • "x/mongo/driver/uuid uses a package-specific random reader, not the global random reader.
  • Seed the "math/rand" pseudo-random number generator with the current time.


 Comments   
Comment by Githook User [ 16/Nov/21 ]

Author:

{'name': 'Matt Dale', 'email': '9760375+matthewdale@users.noreply.github.com', 'username': 'matthewdale'}

Message: GODRIVER-2223 Fix data races caused by unsynchronized access to rand.Rand instances. (#808)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/10abf0f63e0cd655ad26d0294540e05138138c1b

Comment by Githook User [ 12/Nov/21 ]

Author:

{'name': 'Matt Dale', 'email': '9760375+matthewdale@users.noreply.github.com', 'username': 'matthewdale'}

Message: GODRIVER-2223 Use separate, seeded pseudo-random sources for each package. (#803)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/5cab184acf1bc253d0aa51b222bfecdf8927ff8a

Comment by Matt Dale [ 11/Nov/21 ]

PR: https://github.com/mongodb/mongo-go-driver/pull/803

Slight deviation from the definition of done:

  • Uses a separate pseudo-random number source for each package that currently uses "math/rand" instead of seeding the global source.
Generated at Thu Feb 08 08:38:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.