Repository navigation
Conversation
Message files were named <ms>_<uuid4>.<queue>.msg and _get() sorts the names as text, so messages published in the same millisecond came out in uuid (random) order, and the order also broke whenever the millisecond counter gained a digit (9999 sorts after 10000). Zero-pad the millisecond prefix and add a per-process sequence number before the uuid.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Taltal · project thread
Problem
The filesystem transport names each message file
<ms>_<uuid4>.<queue>.msg, where<ms>isint(round(monotonic() * 1000)), and_get()takes the first name aftersorted(os.listdir(...)). That is a text sort, so:[0, 5, 4, 2, 3, 1, 6, 12, 7, 10, ...];10000_...sorts before9999_....Fix
Zero-pad the millisecond prefix and add a per-process sequence number (
itertools.count()) between it and the uuid. Within one process the names now sort in publish order. Across processes, order is still by millisecond, as before._get(),_size()and_purge()are unchanged: they still match on what follows the first..Upgrade note: while files with the old unpadded names are still in the folder, new files (with a leading
0) sort before them. Old messages are still delivered; only their order relative to new ones changes during the switch.Tests
test_messages_are_consumed_in_publish_orderpatchesmonotonicfor two cases: ten messages in the same millisecond, and the counter going from 9999 to 10004. Both fail onmain(7dca15a6) and pass with the fix.t/unit/transport/test_filesystem.py: 221 passed.t/unit(with--continue-on-collection-errors, because the SQS/Azure extras are not installed here): 1573 passed, 186 skipped. One failure,test_FilesystemOpenErrors::test_get_closes_file_when_read_fails, fails onmaintoo, and only in the full run (it passes when the file runs alone).flake8andpydocstyleare clean on the changed files.mypy kombu/transport/filesystem.pyreports the same 22 errors as onmain.I used Claude Code to help find and write this fix. I reviewed and tested the change.