fix(libkernel): keep the Windows vnode watch when the watched file is deleted #5393
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5393"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by yixx16 on 2026-10-13T18:41:44Z.
What
On Windows 10 1903 and later,
DeleteFileWand_wremovedelete with POSIX semantics: a file with open handles is moved into\$Extend\$Deleteduntil its last handle closes. TheEVFILT_VNODEwatch thread keeps a handle on the watched file and takesGetFileInformationByHandleExsnapshots every 50 ms, so after the title deletes a watched file the next snapshot sees a new final path (\\?\C:\$Extend\$Deleted\<id>, 0 links, delete pending), replaces the parent directory watch with one on that directory, getsERROR_ACCESS_DENIEDfromFindFirstChangeNotificationand throws from the detached watch thread, which aborts the process. The path change was also reported asNOTE_RENAMEnext toNOTE_DELETE.A snapshot with a pending delete or no links now reports
NOTE_DELETEalone and drops the parent directory watch instead of replacing it: the file has no directory left to be renamed or removed from, and its own handle keeps reporting until the knote is deleted. The vnode entry indocs/dev/debt/libkernel.mdrecords the behaviour.Measured on Windows 11 with a probe (second handle with
FILE_SHARE_DELETE, thenDeleteFileWor_wremove):GetFinalPathNameByHandleWreturns\\?\C:\$Extend\$Deleted\<id>,FileStandardInforeportsNumberOfLinks0 andDeletePending1, andFindFirstChangeNotificationWon\\?\C:\$Extend\$Deleted\fails with error 5. The same abort appeared as an intermittentguest_kqueuefailure (EVFILT_VNODE: FindFirstChangeNotification failed, error=5, exit 0xc0000409) on a Windows CI run of my fork at the end of a vnode test, where the kqueue is closed and the file removed right after, with the watch thread still in a snapshot.Tested
guest_kqueuegainsDeleteWatchedFile, registered on Linux and Windows: a watched file is unlinked while open,NOTE_DELETEis reported once withoutNOTE_RENAME, nothing more is reported afterwards, and the descriptor and the kqueue close normally.Full Linux and Windows builds with every test on my fork's GitHub Actions
Buildworkflow (1077 and 1095 tests, all passed; this branch together with three kqueue branches of mine): https://github.com/yixx16/AnyPS5/actions/runs/38445944846. The Windows abort without the fix is in the first attempt of https://github.com/yixx16/AnyPS5/actions/runs/38437850775 (jobwindows,guest_kqueue). No title run.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by likecrank-dotcom on 2026-10-13T18:53:57Z.
Independent Windows stress validation by OpenAI Codex (AI-assisted). No code changes were made to this PR.
Validated PR head
50b06110bbac6e37fad8c3dcb55fbecac1843134on Windows 11 Pro build 26100 with WinLibs MinGW GCC 15.2.0 and CMake 4.4.4. Builtguest_kqueue_tests; CTestguest_kqueuepassed 20 consecutive full-suite runs (28.18 seconds total, 20/20). This includes the newDeleteWatchedFileregression.tools/check_conventions.pyagainst base18c438b1092b09cef54e4cfacab441c009a6b501andgit diff --checkpassed. This is a focused repeated test, not a full build or title run.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T19:10:24Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libkernel.mdL97-98docs/dev/debt/libkernel.mdL97-98docs/dev/debt/libkernel.mdL97-98core/libs/tests/GuestKqueue.cppL402, L425docs/dev/debt/libkernel.mdL97-98core/libs/tests/GuestKqueue.cppL402, L425docs/dev/debt/libkernel.mdL98Imported from boykopovar/AnyPS5. Originally posted by yixx16 on 2026-10-13T20:12:42Z.
The overlap with #5361 is only the adjacent line of
docs/dev/debt/libkernel.md: it edits the kqueue entry and this PR the EVFILT_VNODE entry below it. The code is unrelated, so this does not depend on #5361; whichever lands second rebases the debt line.Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-13T20:50:44Z.
Independent confirmation on Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, full build (AI-assisted: Claude Code).
Without the fix, enabling the existing
RenameAndDeleteWatchedFiletest on Windows (it is under#ifndef _WIN32today) abortsguest_kqueuedeterministically withEVFILT_VNODE: FindFirstChangeNotification failed, error=5, exit 0xc0000409, the same failure as #5435.With the same change as this PR (
Deleted= delete pending or 0 links; noNOTE_RENAMEand no parent rewatch when deleted),RenameAndDeleteWatchedFilepasses on Windows:NOTE_RENAMEafter the rename, thenNOTE_DELETEalone after the unlink.guest_kqueuepassed 30/30 withctest --repeat until-fail:30, and the full suite 1098/1098.Since that test now passes on Windows, it could move out of the
#ifndef _WIN32block (onlyMoveDirectoryEntriesneeds to stay Linux-only), either here or in a follow-up after this lands.