[Bug 59722] New: RemoveDirectoryW fails with ERROR_SHARING_VIOLATION after subprocess exit
http://bugs.winehq.org/show_bug.cgi?id=59722 Bug ID: 59722 Summary: RemoveDirectoryW fails with ERROR_SHARING_VIOLATION after subprocess exit Product: Wine Version: 11.8 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: kernel32 Assignee: wine-bugs@list.winehq.org Reporter: joel@airwebreathe.org.uk Distribution: --- Created attachment 80868 --> http://bugs.winehq.org/attachment.cgi?id=80868 reproducer.c (Found by AI testing) After a subprocess exits that had its current working directory set to a given directory, `RemoveDirectoryW()` on that directory fails with `ERROR_SHARING_VIOLATION` (error code 32). Wine does not properly release the directory handle that was used as the subprocess's CWD after the process terminates. On real Windows, removing the directory succeeds immediately after the subprocess exits. ## Impact on MSYS2 The MSYS2/Cygwin runtime maps `ERROR_SHARING_VIOLATION` to `EBUSY` (errno 16). Many MSYS2 test suite tests create a temporary directory, `fork()` + `exec()` a child process (which inherits the CWD), wait for the child to exit, then call `rmdir()` to clean up. Under Wine, this cleanup fails with `EBUSY`, causing the test harness to report failures even though the actual test logic passed. Affected tests include: | Test | Symptom | |------|---------| | fcntl07 | All 2 test cases PASS, but cleanup rmdir fails with EBUSY | | fcntl07B | Test case PASSES, but cleanup rmdir fails with EBUSY | ## Reproducer ``` x86_64-w64-mingw32-gcc -o reproducer.exe reproducer.c -lntdll wine reproducer.exe ``` ### Expected output (real Windows) ``` === Test 3: rmdir after subprocess with CWD in target dir === PASS: CreateDirectory PASS: RemoveDirectory after subprocess exit ``` ### Actual output (Wine 11.4) ``` === Test 3: rmdir after subprocess with CWD in target dir === PASS: CreateDirectory FAIL: RemoveDirectory after subprocess exit (GetLastError=32) Error: 32 ``` Error 32 is `ERROR_SHARING_VIOLATION`, indicating Wine still holds an internal reference to the directory after the subprocess has exited. ## Analysis When Wine creates a process with a CWD in a target directory, it opens a handle to that directory. When the process exits, Wine should close this handle so that the directory is no longer held open. Instead, the handle appears to leak or be released asynchronously, causing an immediate `RemoveDirectoryW` to hit a sharing violation. The underlying NT status is `STATUS_SHARING_VIOLATION`, which occurs because the directory still has an open handle without compatible sharing modes. ## Environment - Wine: 11.4 - Host: Linux x86_64 -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59722 Joel Holdsworth <joel@airwebreathe.org.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bernhardu@mailbox.org -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59722 --- Comment #1 from Joel Holdsworth <joel@airwebreathe.org.uk> --- Created attachment 80871 --> http://bugs.winehq.org/attachment.cgi?id=80871 reproducer.exe -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59722 --- Comment #2 from Bernhard Übelacker <bernhardu@mailbox.org> --- Created attachment 80879 --> http://bugs.winehq.org/attachment.cgi?id=80879 debugging.txt Hello, I tried if I could debug this and here calling the reproducer.exe from a unix terminal gets me two conhost.exe processes. The second gets started in cmd.exe in init_console/alloc_console. This second conhost.exe gets started with current directory in cwd_test, therefore the directory cannot be deleted. Attached file contains some notes with backtraces of interesting events. At the bottom is s simple patch to start the conhost processes with current directory of c:\windows\system32, and it stopped showing me the failure on RemoveDirectory. Can you please check if this fixes the issue also with msys2? -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59722 --- Comment #3 from Joel Holdsworth <joel@airwebreathe.org.uk> --- The patch definitely provides a benefit in msys2-tests: | Test | Before | After | Root cause | |------------|---------------|-------|--------------------------------------------------------------------| | `fcntl07` | FAIL (exit 4) | PASS | `rmdir()` failed with `errno=16: Device or resource busy` | | `fcntl07B` | FAIL (exit 4) | PASS | same - `rmdir()` EBUSY on temp dir | | `devdsp` | TIMEOUT | PASS | fork+play test hung (child process blocked by conhost holding CWD) | I will include it in the next msys2-hacks release, and I think this should go upstream also. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59722 --- Comment #4 from Bernhard Übelacker <bernhardu@mailbox.org> --- (In reply to Joel Holdsworth from comment #3)
The patch definitely provides a benefit in msys2-tests:
Thanks for testing, I submitted a merge request: https://gitlab.winehq.org/wine/wine/-/merge_requests/10832 -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59722 --- Comment #5 from Bernhard Übelacker <bernhardu@mailbox.org> --- Hello Joel, the merge request got accepted. Thanks for the nice reproducer, was a pleasure to debug :-) I guess we are done now with this bug report? -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59722 --- Comment #6 from Joel Holdsworth <joel@airwebreathe.org.uk> --- Yup you fixed it. Great job! Amazing to see this done so quickly. I'm doing a lot of AI-assisted bug hunting this week. I reported the status of what I have discovered so far here: https://github.com/msys2/MSYS2-packages/issues/682 , if you're interested. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59722 Bernhard Übelacker <bernhardu@mailbox.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Fixed by SHA1| |b39663ddd80951d282f911dd6a9 | |4fb45c71c7ddf Resolution|--- |FIXED --- Comment #7 from Bernhard Übelacker <bernhardu@mailbox.org> --- Thank you, marking resolved-fixed. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
participants (1)
-
WineHQ Bugzilla