0

I'm getting a lot of collisions, at least 5 on the last 100.000 generated UUID. Right now wea are checking that generated UUID with a redis instance, so if a collision happen, we can regenerate it.

The service has at least 2 instances always running.

the UUID is generated with

crypto.randomUUID()
CNK
  • 122
  • 2
  • 11
  • Are you **seeding** the random number generator first? Otherwise, you will have predictable pseudo random numbers which UUID uses. – John Hanley Mar 15 '22 at 22:22
  • @JohnHanley but I'm using the "Crypto" library. It's supose to be cryptographically secure – CNK Mar 16 '22 at 13:38
  • I do not use your library, but each one I have used does require seeding the random number generator. The first clue is that you are generating duplicate UUIDs. https://en.wikipedia.org/wiki/Random_seed – John Hanley Mar 16 '22 at 16:20
  • Since you are having UUID collisions that should **never** happen, investigate your code to find out why that is occurring. – John Hanley Mar 16 '22 at 19:15
  • @JohnHanley it's the native method of node – CNK Mar 17 '22 at 04:52
  • That is why I am suggesting your code has the problem. Otherwise, the library has the problem and I doubt that at this point. – John Hanley Mar 17 '22 at 05:51

2 Answers2

1

I can only asume they are looking at this method and it does not allow a seed parameter.

I am not sure why this would happen but might have been coincidence that 5 ids were repeated. I suggest looking at other options people have tried, such as including date.now() in order to truly never get a repeat.

Hipster Cat
  • 331
  • 2
  • 11
  • Well, Looking the the docs that you posted, I see that it has by default a "cache of random data". So I will test again with it disabled crypto.randomUUID({ disableEntropyCache: true }) – CNK Mar 17 '22 at 04:55
0

In UUID's npm page shows support only up to node 14, is that the problem? https://www.npmjs.com/package/uuid

  • I'm not using a package, is the oficial crypto module from node, currently suppoerted ( https://nodejs.org/api/crypto.html ) – CNK Aug 28 '22 at 07:33