Windows Terminal leaks a file handle to the starting directory #14758

Open
opened 2026-01-31 04:18:42 +00:00 by claunia · 0 comments
Owner

Originally created by @zomgrolf on GitHub (Aug 2, 2021).

Windows Terminal version (or Windows build number)

1.9.1942.0 (Windows version: 10.0.19043.1110)

Other Software

No response

Steps to reproduce

  1. Create an empty directory, e.g. c:\temp\rmdir_test
  2. Open explorer.exe and navigate to the newly created directory.
  3. In the address bar, type wt -d . to launch a new instance of Windows Terminal with Command Prompt as the default profile.
  4. Close the explorer window.
  5. In the command prompt type cd .. to go the the directory above (c:\temp).
  6. Type rmdir rmdir_test to attempt to delete the empty rmdir_test directory

Expected Behavior

I was expecting to be able to delete the rmdir_test directory without having to close the terminal window.
If I repeat the above steps using conhost instead of Windows Terminal (i.e. typing cmd.exe in the address bar instead of wt -d .), I can delete that directory just fine, with the command prompt still open.

Actual Behavior

I get the following error: The process cannot access the file because it is being used by another process.

If I look for the handle in Resource Monitor, I get this:
resmon

It seems that the Terminal retains that file handle for as long as the process is alive, even if I navigate away from the starting directory.

Seems to be similar to #9664, which was marked as resolved and closed, although I don't really see any solutions in there that would be applicable in my case...

Originally created by @zomgrolf on GitHub (Aug 2, 2021). ### Windows Terminal version (or Windows build number) 1.9.1942.0 (Windows version: 10.0.19043.1110) ### Other Software _No response_ ### Steps to reproduce 1. Create an empty directory, e.g. c:\temp\rmdir_test 2. Open explorer.exe and navigate to the newly created directory. 3. In the address bar, type `wt -d .` to launch a new instance of Windows Terminal with Command Prompt as the default profile. 4. Close the explorer window. 5. In the command prompt type `cd ..` to go the the directory above (`c:\temp`). 6. Type `rmdir rmdir_test` to attempt to delete the empty `rmdir_test` directory ### Expected Behavior I was expecting to be able to delete the `rmdir_test` directory without having to close the terminal window. If I repeat the above steps using conhost instead of Windows Terminal (i.e. typing `cmd.exe` in the address bar instead of `wt -d .`), I can delete that directory just fine, with the command prompt still open. ### Actual Behavior I get the following error: `The process cannot access the file because it is being used by another process.` If I look for the handle in Resource Monitor, I get this: <img width="891" alt="resmon" src="https://user-images.githubusercontent.com/38769102/127894222-6b7b0a8d-2564-4283-9913-235167578f40.png"> It seems that the Terminal retains that file handle for as long as the process is alive, even if I navigate away from the starting directory. Seems to be similar to #9664, which was marked as resolved and closed, although I don't really see any solutions in there that would be applicable in my case...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#14758