Repository navigation
OLD-9215: restore old upstream PR 9215 - file_system: RemoveDirectory and a create inside the folder are ordered as on the host - #688
Merged
Conversation
…ed as on the host Restores old upstream PR 9215 in ItsNotRexed/Leonida (closed unmerged when that repository went private), ported onto the current main: the write-open keeps main's long-path disk_path() for its overlay path, and the new race test sits after main's tests that recreate a removed package folder. A GAME: write-open checked that its folder exists, mirrored it into the overlay and then opened the file, and RemoveDirectory checked that the folder was empty and wrote its marker, neither under a lock. A remove that ran between the open's check and its host CreateFile succeeded on an empty folder, and the open then made the folder and the file again: both calls succeeded and the removed folder was back. CreateDirectory of a folder inside it had the same gap. On Windows one of the two fails: the create with ERROR_PATH_NOT_FOUND or the remove with ERROR_DIR_NOT_EMPTY. A striped lock keyed by the folder's upper-cased name (64 namespace-scope std::mutex, no function-local static): write_target holds the lock of the folder it opens in from the parent check until the Target is gone, after the host CreateFile/CreateFile2; CreateDirectory holds the parent's from its check to the host call; RemoveDirectory holds the folder's from its view to the marker. Reads take no lock. file_system_test races the two calls on two threads, 2,000 rounds each for a creating CreateFileW (CREATE_NEW, CREATE_ALWAYS, OPEN_ALWAYS) and for CreateDirectoryW, and checks that they never both succeed, that the loser fails with the host's error and that a removed folder stays removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
abnalstlll-byte
approved these changes
Nov 24, 2026
abnalstlll-byte
left a comment
Contributor
There was a problem hiding this comment.
Technical Review: APPROVE (OLD-9215)
-
Concurrency Correctness:
- Eliminates the race condition where simultaneous GAME: RemoveDirectory and CreateDirectory/CreateFile inside the folder both succeed, resulting in resurrected deleted folders.
- Striped 64-mutex locking keyed by folder name ensures fine-grained synchronization with zero lock contention across unrelated folder trees.
- Comprehensive synthetic multithreaded race test in runtime/test/file_system_test.cpp (2,000 stress iterations, 0 double-successes).
-
Clean-Room & Verification:
- Clean-room confirmed via check_no_game_data.py.
- Clean merge against main at 21625bc (0 conflicts).
LGTM!
This was referenced Nov 25, 2026
Collaborator
Author
3 of 4 tasks
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.
Claimed in the coordination issue as: OLD-9215 #14 (comment)
Restoration of my original pull request, old upstream PR 9215 in
ItsNotRexed/Leonida, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Ported onto main at 21625bc; the write-open keeps main's long-pathdisk_path()for its overlay path, and the new race test sits after main's tests that recreate a removed package folder. Nothing else changed from the original.What and why
GAME:write-open orCreateDirectory*inside a folder could run its "does the folder exist" check, and then aRemoveDirectory*of that folder on another thread could run its emptiness check and write its marker. No lock covered either step.ERROR_PATH_NOT_FOUND, or the remove withERROR_DIR_NOT_EMPTY.std::mutex(no function-local static).write_targetholds the lock of the folder it opens in, from the parent check until theTargetis gone after the hostCreateFile/CreateFile2.CreateDirectory*holds the parent's lock from its check to the host call, which includes main's marker clean-up.RemoveDirectory*holds the folder's lock from its view to the marker.file_system_testraces the two calls on two threads, 2,000 rounds for a creatingCreateFileW(CREATE_NEW,CREATE_ALWAYS,OPEN_ALWAYS) and 2,000 forCreateDirectoryW. It checks three things: the two never both succeed, the loser fails with the host's error, and a removed folder stays removed.docs/runtime_imports.mddescribes the ordering.CreateDirectoryof a removed package folder X racingRemoveDirectoryof X itself. Main'sCreateDirectorydeletes X's removal marker after it makes the overlay folder, and a remove in between leaves X visible again although both calls succeeded.Tested
Linux, Wine 11.22 (Staging),
file_system_testbuilt with clang 23 forx86_64-w64-mingw32. MSVC/W4 /permissive-is left to CI.MAXIMUM_ALLOWEDopens, long paths, and the hostReadFileERROR_NOACCESSprobe.CreateFileW: both calls succeeded in 1,972 of 2,000 rounds.CreateDirectoryW: both calls succeeded in 1,012 of 2,000 rounds.CreateFileW: create first 1,964, remove first 36, both 0.CreateDirectoryW: remove first 2,000, both 0.git diff --checkis clean, andpython -I scripts/check_no_game_data.pypasses on the three changed files.git merge-treeshows no conflict with the other open pull requests that touchfile_system.cpp: OLD-8161: restore old upstream PR 8161 - file_system: T: is a folder of each process's own in the overlay #684, mfplat_offline: add offline Media Foundation source-resolver proxy and console path rewrite (RT-MF-OFFLINE) #400, file_system: GetVolumeInformation and GetVolumePathName answer for the GAME: and T: roots #317, file_system: GetTempPath and GetTempFileName resolve GAME:, G: and T: to the overlay scratch folder #287, file_system: a GAME: name inside a missing folder fails with ERROR_PATH_NOT_FOUND, as on the host #271 and runtime: unified loader/OS perf pack (console paths, per-DLL import cache, SHA-NI, lock-free registry) #115.GPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.AI-assisted (Claude Code, Claude Opus 5.5).