Bug report
Bug description:
Running uuid.uuid1 concurrently in multiple parallel python processes on Windows creates colliding UUIDs, due to the timestamps colliding. Can be seen with 10-20 concurent processes usually.
This is unnecessary, as python already wraps the UuidCreateSequential() API
|
res = UuidCreateSequential(&uuid); |
, but then discards the time part and falls back to some collision prone time code in
|
# use UuidCreate here because its UUIDs don't conform to RFC 4122). |
due to a claim that UuidCreate() does not follow RFC 4122.
But as far as i can tell, Windows UuidCreateSequential() does follow RFC 4122 by now, tested on Win10, so the comment looks wrong or badly aged. It is true, that the function returns the bytes in the wrong order, Little Endian, instead of the RFC prescribed Big Endian, but the rest looks sane.
This works just fine and creates a UUID thats pretty similar to the ones created by the current uuid.uuid1 implementation.
>>> import _uuid
>>> import uuid
>>> win_uuid = uuid.UUID(bytes_le=_uuid.UuidCreate())
>>> win_uuid.version
1
>>> win_uuid.variant
'specified in RFC 4122'
>>> win_uuid.time
139348915287723566
>>> win_uuid.node
185263057677337
>>> py_uuid = uuid.uuid1()
>>> py_uuid.version
1
>>> py_uuid.variant
'specified in RFC 4122'
>>> py_uuid.time
139348915744502628
>>> py_uuid.node
185263057677337
I would propose to remove the unsafe time fallback for Windows and use the results of UuidCreate() to make it safe.
CPython versions tested on:
3.11
Operating systems tested on:
Windows
Linked PRs
Bug report
Bug description:
Running
uuid.uuid1concurrently in multiple parallel python processes on Windows creates colliding UUIDs, due to the timestamps colliding. Can be seen with 10-20 concurent processes usually.This is unnecessary, as python already wraps the
UuidCreateSequential()APIcpython/Modules/_uuidmodule.c
Line 63 in 9c15202
, but then discards the time part and falls back to some collision prone time code in
cpython/Lib/uuid.py
Line 668 in b4ca389
But as far as i can tell, Windows UuidCreateSequential() does follow RFC 4122 by now, tested on Win10, so the comment looks wrong or badly aged. It is true, that the function returns the bytes in the wrong order, Little Endian, instead of the RFC prescribed Big Endian, but the rest looks sane.
This works just fine and creates a UUID thats pretty similar to the ones created by the current
uuid.uuid1implementation.I would propose to remove the unsafe time fallback for Windows and use the results of UuidCreate() to make it safe.
CPython versions tested on:
3.11
Operating systems tested on:
Windows
Linked PRs