Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: UUIDs not unique if using a 2023 Hermes JS implementation #36

Closed
cokron opened this issue Oct 16, 2024 · 1 comment
Closed

Comments

@cokron
Copy link

cokron commented Oct 16, 2024

Hey folks,

we have generated close to 100.000 uuids in our react native app on our user's iOS and Android phones.

We have had a handful of UUID collisions.

As written in the README and as can be seen in the source code, react-native-uuid is using Math.random() to generate UUIDs.

The quality of the UUIDs hence depends on the quality of the implementation of Math.random().

Trying to understand why we were seeing UUID collisions, I investigated into the implementation of the Hermes JS Engine that is used by default by react native and found this:

facebook/hermes#1169

The author of this bug ticket writes:

As you can see, it uses std::random_device() as seed. It is an unsigned int and therefore there are only about 4B possible values. There is a 71% chance of a single collision if you generate 100k values using the Birthday problem formulation. So many different instances of this will go through the exact same sequence. While this is not used for security, this is also unusable for things like UUID v4 generation since there will be tons of collisions.

This has been improved in commit
facebook/hermes@34f0b2b

which was merged into Hermes on 2023-10-31.

We had been using a Hermes 0.72.4, which is older than that date. Look into ios/Podfile.lock if you want to find out which version you are using.

We have now updated to a more up to date Hermes, which will supposedly solve the issue with duplicate UUIDs.

Thank you very much, Eugene, for writing this easy to use library!

I feel it is important for people using react-native-uuid to be warned about having to update their Hermes version to avoid duplicate uuids. So, please either let this issue live for some time until most people have upgraded or add a note in the README or use an implementation other than Math.random().

@eugenehp
Copy link
Owner

eugenehp commented Oct 16, 2024 via email

@eugenehp eugenehp closed this as completed Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants