{"data":{"id":"magento2-39372","source":"github-pr","sourceRef":"magento/magento2#39372","title":"When using file storage for the lock provider, we get an ever growing directory of files without any cleanup happening","pr":{"number":39372,"url":"https://github.com/magento/magento2/pull/39372","author":"hostep","mergedAt":"2025-04-02T23:52:44Z","mergeCommit":"292769ae2873ef6e34f7f35fbb259d4de53ae4e7","headCommit":"b635942d9e077b34d1e72b76aa0262ab7f09f1ad","baseRef":"2.4-develop","diffSha256":"a8f56c6794f582faf5956a0dddd2723905c55a917a8d1d85bdcea07b3a10fd35"},"issues":[{"number":39369,"url":"https://github.com/magento/magento2/issues/39369","title":"When using file storage for the lock provider, we get an ever growing directory of files without any cleanup happening","labels":["Area: Framework","Component: Backend","Issue: Confirmed","Priority: P2","Progress: PR in progress","Progress: done","Reported on 2.4.x","Reproduced on 2.4.x","Triage: Dev.Experience"],"kind":"human"}],"fixedIn":"2.4.9","containingTags":["2.4.9"],"reportedOn":null,"codeMatch":{"2.4.6":"clean","2.4.6-p1":"clean","2.4.6-p2":"clean","2.4.6-p3":"clean","2.4.6-p4":"clean","2.4.6-p5":"clean","2.4.6-p6":"clean","2.4.6-p7":"clean","2.4.6-p8":"clean","2.4.6-p9":"clean","2.4.6-p10":"clean","2.4.6-p11":"clean","2.4.6-p12":"clean","2.4.6-p13":"clean","2.4.6-p14":"clean","2.4.6-p15":"clean","2.4.7":"clean","2.4.7-p1":"clean","2.4.7-p2":"clean","2.4.7-p3":"clean","2.4.7-p4":"clean","2.4.7-p5":"clean","2.4.7-p6":"clean","2.4.7-p7":"clean","2.4.7-p8":"clean","2.4.7-p9":"clean","2.4.7-p10":"clean","2.4.8":"clean","2.4.8-p1":"clean","2.4.8-p2":"clean","2.4.8-p3":"clean","2.4.8-p4":"clean","2.4.8-p5":"clean","2.4.9":"conflict"},"affectedVersions":["2.4.6","2.4.6-p1","2.4.6-p2","2.4.6-p3","2.4.6-p4","2.4.6-p5","2.4.6-p6","2.4.6-p7","2.4.6-p8","2.4.6-p9","2.4.6-p10","2.4.6-p11","2.4.6-p12","2.4.6-p13","2.4.6-p14","2.4.6-p15","2.4.7","2.4.7-p1","2.4.7-p2","2.4.7-p3","2.4.7-p4","2.4.7-p5","2.4.7-p6","2.4.7-p7","2.4.7-p8","2.4.7-p9","2.4.7-p10","2.4.8","2.4.8-p1","2.4.8-p2","2.4.8-p3","2.4.8-p4","2.4.8-p5"],"components":["magento/framework","magento/module-backend"],"files":[{"path":"app/code/Magento/Backend/Cron/CleanLocks.php","change":"added","package":"magento/module-backend"},{"path":"app/code/Magento/Backend/etc/crontab.xml","change":"modified","package":"magento/module-backend"},{"path":"lib/internal/Magento/Framework/Lock/Backend/FileLock.php","change":"modified","package":"magento/framework"}],"stripped":{"tests":["dev/tests/integration/testsuite/Magento/Framework/Lock/Backend/FileLockTest.php"],"docs":[],"outsideCode":[]},"linesChanged":95,"mergeBatched":false,"excluded":null,"sections":{"description":"- `var/locks` can contain up to millions of files after several months of running a Magento shop","stepsToReproduce":"1. Setup clean Magento with sample data\n2. Make sure cronjobs are running\n3. From the root of Magento, execute these commands:\n```\n$ mkdir \"$(pwd)/var/locks\"\n$ bin/magento setup:config:set --lock-provider=file --lock-file-path=\"$(pwd)/var/locks\"\n$ bin/magento cache:enable\n$ bin/magento cache:flush\n```\n4. Start visiting the frontend, please visit many different pages: homepage, category pages, product detail pages, ...\n5. Also create some orders\n6. Look at the contents of the `var/locks` directory\n\nIdeally you should look at a shop running for many months and where file based locking has been enabled, and inspect the directory that contains those lock files.","expectedResult":"- `var/locks` directory should not overflow with an ever increasing amount of files","actualResult":"- `var/locks` can contain up to millions of files after several months of running a Magento shop\n\nExample filenames:\n```\n- BLOCK_833608638be7d42c9a8edf79b3516f6768babb37b07cb0c924ce1ede8c7b60f4-122217-final_price-EUR-20241114-1-0-\n- BLOCK_8c40abe5c67c542dd31f6ed0787db94f9b6c7add8c7eccb4aeff4dc1adb10d9d-122217\n- BLOCK_833608638be7d42c9a8edf79b3516f6768babb37b07cb0c924ce1ede8c7b60f4-122209-final_price-EUR-20241114-1-0-\n- BLOCK_8c40abe5c67c542dd31f6ed0787db94f9b6c7add8c7eccb4aeff4dc1adb10d9d-122209\n- BLOCK_833608638be7d42c9a8edf79b3516f6768babb37b07cb0c924ce1ede8c7b60f4-122213-final_price-EUR-20241114-1-0-\n- BLOCK_8c40abe5c67c542dd31f6ed0787db94f9b6c7add8c7eccb4aeff4dc1adb10d9d-122213\n- BLOCK_833608638be7d42c9a8edf79b3516f6768babb37b07cb0c924ce1ede8c7b60f4-122194-final_price-EUR-20241114-1-0-\n- BLOCK_0dececc6f6ab51b0dc125a1d40b7c4fd8dac44300acc9927a9bbc923f0dc4b1d-122201-final_price-EUR-20241114-1-0-\n- BLOCK_fd38c4b3f09eb9f6357edad8fbb6fa37f447f4b29367471c1f63330cfd2e6041\n- BLOCK_2b0ceeddda2b7376874129eed2893a53db19081fd2ff426fc9a63a3ad80125d3\n- PLACE_ORDER_20194\n- PLACE_ORDER_20197\n- PLACE_ORDER_20199\n- PLACE_ORDER_20201\n- CRON_54ca823af2ab2bc8e0923548a617e1d9\n- CRON_597b39571a8e2e02aa3da5b0b669058c\n- CRON_5d6e389185b7c7ff8ada1b70e5d5beec\n- CRON_5dc531608e6750f85d979bb963298bd3\n- CRON_65418d1532274c42fbc28425e8b9b7f1\n- CRON_65541ac6ef52e06c546be79471cf53ce\n- indexer_lock_category_product\n- SYSTEM_CONFIG\n```\n\nWe had one project that had 3.5 million files in that directory, up to a point where the filesystem started complaining with errors like `Failed to open stream: No space left on device` every time a lock file was needed (there was plenty of disk space, it's just that a directory can't handle that large amount of files in one directory). Another project had 1.9 million files and another had ~170.000 files.\n\nSo that's really bad. We need some kind of bugfix or cleanup mechanism to keep this under control.","source":"issue"},"signatures":[],"labels":{"area":["Framework"],"component":["Backend"],"priority":"P2","severity":null,"reportedOn":["2.4.x"]},"categories":[],"triage":{"model":"@cf/cloudflare/clef","requestHash":"b65eedf5a8dcdc764dfece134a172c969cf0b3228e2917ce6a734b1b03195cf4","isBugfix":0.8641,"changeKind":{"choice":"bugfix","probabilities":{"bugfix":0.7596,"feature":0.197,"refactor":0.0208,"tests_only":0.0132,"docs_only":0.0041,"dependency":0.0053},"confidence":0.5397},"scope":{"score":0.9557,"probabilities":{"0":0.2521,"1":0.5401,"2":0.2078},"confidence":0.0977},"risk":{"score":0.3984,"probabilities":{"0":0.6571,"1":0.2874,"2":0.0555},"confidence":0.2762},"area":{"choice":"framework","probabilities":{"catalog":0.0074,"checkout":0.0094,"customer":0.0046,"admin":0.0311,"graphql_api":0.0036,"framework":0.9169,"frontend":0.0116,"other":0.0154},"confidence":0.8196},"securityRelevant":0.0064,"reportedVersion":{"choice":"2.4.7-p3","probabilities":{"2.4.0":0.0015,"2.4.0-p1":0.0015,"2.4.1":0.0014,"2.4.1-p1":0.0013,"2.4.2":0.0016,"2.4.2-p1":0.0018,"2.4.2-p2":0.0025,"2.4.3":0.0025,"2.4.3-p1":0.0027,"2.4.3-p2":0.0044,"2.4.3-p3":0.0031,"2.4.4":0.0049,"2.4.4-p1":0.0031,"2.4.4-p10":0.0027,"2.4.4-p11":0.0042,"2.4.4-p12":0.004,"2.4.4-p13":0.0046,"2.4.4-p14":0.0033,"2.4.4-p15":0.0033,"2.4.4-p16":0.0032,"2.4.4-p17":0.0045,"2.4.4-p18":0.0022,"2.4.4-p2":0.0014,"2.4.4-p3":0.0016,"2.4.4-p4":0.002,"2.4.4-p5":0.0024,"2.4.4-p6":0.0029,"2.4.4-p7":0.0034,"2.4.4-p8":0.0032,"2.4.4-p9":0.0021,"2.4.5":0.006,"2.4.5-p1":0.0031,"2.4.5-p10":0.0028,"2.4.5-p11":0.0043,"2.4.5-p12":0.0047,"2.4.5-p13":0.0038,"2.4.5-p14":0.004,"2.4.5-p15":0.0026,"2.4.5-p16":0.0026,"2.4.5-p17":0.0032,"2.4.5-p2":0.002,"2.4.5-p3":0.0019,"2.4.5-p4":0.0022,"2.4.5-p5":0.0022,"2.4.5-p6":0.0029,"2.4.5-p7":0.0028,"2.4.5-p8":0.0026,"2.4.5-p9":0.002,"2.4.6":0.0853,"2.4.6-p1":0.0161,"2.4.6-p10":0.0119,"2.4.6-p11":0.0097,"2.4.6-p12":0.0081,"2.4.6-p13":0.008,"2.4.6-p14":0.0078,"2.4.6-p15":0.006,"2.4.6-p2":0.0046,"2.4.6-p3":0.0125,"2.4.6-p4":0.0127,"2.4.6-p5":0.0093,"2.4.6-p6":0.0092,"2.4.6-p7":0.0101,"2.4.6-p8":0.0071,"2.4.6-p9":0.0042,"2.4.7":0.1088,"2.4.7-p1":0.0301,"2.4.7-p10":0.0083,"2.4.7-p2":0.0134,"2.4.7-p3":0.2727,"2.4.7-p4":0.0204,"2.4.7-p5":0.0131,"2.4.7-p6":0.0098,"2.4.7-p7":0.0084,"2.4.7-p8":0.0065,"2.4.7-p9":0.0039,"2.4.8":0.0033,"2.4.8-p1":0.0038,"2.4.8-p2":0.0052,"2.4.8-p3":0.0051,"2.4.8-p4":0.0056,"2.4.8-p5":0.0054,"2.4.9":0.0033,"unspecified":0.1113},"confidence":0.099},"backportWorthy":{"score":1.6141,"probabilities":{"0":0.0707,"1":0.2446,"2":0.6847},"confidence":0.3005}},"curated":{"title":"Fixes the ever growing var/locks directory with file based locking","description":"With the file based lock provider, var/locks can contain up to millions of files after several months, with no cleanup. The new backend_clean_locks cron job (Magento\\Backend\\Cron\\CleanLocks) runs once per day and, only when FileLock is used, deletes lock files that are 0 bytes, unlocked and not modified in the last 24 hours.","categories":[],"author":"claude-code/opus-5.5","date":"2026-10-06","reviewedBy":null},"tests":{"2.4.8-p5":{"before":"not-runnable","after":"pass","adapted":false,"runAt":"2026-10-06T09:25:14.117Z","releaseCommit":"870a22c63d9d9b68fa3297962e2d5d5841115814","suites":{"integration":{"before":"not-runnable","after":"pass","runAt":"2026-10-06T09:25:14.117Z"}}},"2.4.7-p10":{"before":"not-runnable","after":"error","adapted":false,"runAt":"2026-10-06T09:48:09.803Z","releaseCommit":"72561bf80652f57cc642a03e2c9a51d74a285b14","suites":{"integration":{"before":"not-runnable","after":"error","runAt":"2026-10-06T09:48:09.803Z"}}}}},"_documentation":"https://magento.watch/api","_description":"Upstream fix magento2-39372 details"}