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

Uuid v7 generated in wrong order #536

Open
fannyfan414 opened this issue Feb 7, 2024 · 3 comments
Open

Uuid v7 generated in wrong order #536

fannyfan414 opened this issue Feb 7, 2024 · 3 comments
Labels

Comments

@fannyfan414
Copy link

Hello, I came across a strange case where the library generated uuid v7 incorrectly in time.

Here example of table id = Uuid::uuid7()->toString() and created_at (server datetime), sorted by id (asc)

id, created_at
018d7fca-3ae5-7306-a040-204628e43dc9, 2024-02-06T18:59:36.000000Z
018d7fdc-0ba8-7006-8047-41a572a695c6, 2024-02-06T19:19:03.000000Z
018d8030-0dab-7206-a042-31238ed9cb48, 2024-02-06T20:50:49.000000Z
018d8041-7c1b-7106-8043-6c5e69c8fbbd, 2024-02-06T21:09:51.000000Z
01a6ce4c-5a19-7006-b045-197ad8210718, 2024-02-06T19:19:54.000000Z

For some reason, ID=01a6ce4c-5a19-7006-b045-197ad8210718 was generated incorrectly

@fannyfan414 fannyfan414 added the bug label Feb 7, 2024
@fannyfan414
Copy link
Author

Another wrong generations:

id, created_at
018d8796-b0c2-71ec-a637-7ad6a9a68a3c, 2024-02-08T07:20:16.000000Z
018d8799-185b-72ec-963e-54e7016030d8, 2024-02-08T07:22:54.000000Z
018d8799-5cd1-71ec-863a-f076be6535c6, 2024-02-08T07:23:11.000000Z
018d8799-8d0d-70ec-a637-743e23347b0d, 2024-02-08T07:23:23.000000Z
018d879c-3258-72ec-8638-8a684bdc8bb6, 2024-02-08T07:26:17.000000Z
01f7b992-d225-73ec-863e-d9d832540274, 2024-02-08T07:16:07.000000Z

01f7b992-d225-73ec-863e-d9d832540274 generated from incorrect time

@fannyfan414
Copy link
Author

And one more example (this ids use in messages table), messages sorted by "id", since in theory uuid v7 should be monotonically increasing

Therefore, because of this bug, sometimes the wrong order of messages appears in correspondence

id, created_at
018d8537-8800-71ec-9631-9041bbb08aa2, 2024-02-07T20:17:05.000000Z
018d8537-b73c-72ec-a63c-f0dc35e6eb67, 2024-02-07T20:17:17.000000Z
018d8537-b74e-71ec-8637-616a01cbf9c8, 2024-02-07T20:17:17.000000Z
018d8537-b7ce-73ec-9635-37455306d8bc, 2024-02-07T20:17:17.000000Z
018d855d-4059-72ec-9633-ecea8496ee53, 2024-02-07T20:58:17.000000Z
018d8766-2d2e-73ec-b632-eb1529031055, 2024-02-08T06:27:16.000000Z
01b0b44d-a613-71ec-b637-cbb67c05e163, 2024-02-07T20:24:24.000000Z

018d8766-2d2e-73ec-b632-eb1529031055 and 01b0b44d-a613-71ec-b637-cbb67c05e163 generated incorrectly

@ramsey
Copy link
Owner

ramsey commented Apr 27, 2024

  1. Are these UUIDs all generated on the same machine? Are they generated within the same process?
  2. Are you able to consistently reproduce this issue with a short snippet of code? Can you reproduce it on different machines?
  3. Can you reproduce the issue when generating UUIDv7 using symfony/uid? ramsey/uuid borrows code from symfony/uid, so if you can reproduce it with that library, then both of our libraries have the same bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants