microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
16.94k stars 799 forks source link

WSL2 automounted directories randomly stop working #6448

Open robin865 opened 3 years ago

robin865 commented 3 years ago

I have configured automounts using WSL2:

robinm@dwmsilpt433:/c/github/$ cat /etc/wsl.conf [automount] root = / options = "metadata"

OS: Ubuntu 20.04

I have noticed when working within auto-mounted directories, that randomly I get a variant of these errors:

"OSError: [Errno 2] No such file or directory" "fatal: Unable to read current working directory: No such file or directory"

The workaround is to leave the directory and re-enter it: cd; cd -

However this is really annoying as it regularly causes scripts I am running to fail in weird ways.

dorny commented 3 years ago

I have exactly same issue. Workaround also works for me, but as already said - it's really annoying because it regularly breaks scripts I'm using.

therealkenc commented 3 years ago

Please post the output of:

$ cat /proc/version
$ cmd.exe /c ver

I have noticed when working within

Can you detail the repro for "working within". That error happens "randomly" is understood, but there needs to be at least some command in play to make the submission actionable. It looks to be a Python error. If you are able, catch the command failing and supply a gist of a theaded strace(1) log . Looks like

$ strace -f -o command.strace <your command here>
"OSError: [Errno 2] No such file or directory"
"fatal: Unable to read current working directory: No such file or directory"

A screencap for context sometimes helps as well.

robin865 commented 3 years ago

So the error isn't specific to anything. Once this weirdness has happened, even a simple "ls" fails. Its basically as if you had CD'd into a directory and then someone else deleted that directory.

Ex: "shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory"

In terms of the repro; I think it tends to happen more often when I am executing scripts within that directory. For my purposes, it happens most often when I am running python scripts.

The problem is the error output has nothing to do with the script being run. So I don't think the output at the time of the failure will tell you anything as it . My guess is that the automount is un-mounting then re-mounting for some reason (under the hood).

therealkenc commented 3 years ago

The error caused by a getcwd(2) failing, and some userspace program running inside WSL outputting an error as a result. Catching that fail in an strace(1) log may tell us something, which is why it was requested. The shell-init fail is from /bin/bash. Your OP fail was from a Python script (from the looks).

Please also post the output of in addition to missing information from the deleted template.

$ powershell.exe "Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntivirusProduct"
robin865 commented 3 years ago

Here is that additional info. One question about the strace. Do I need to be running it on the command that causes this issue, or can I run it on an arbitrary command after the issue has occurred? Ex: Once I get the "No such file" error; could I just run: " strace -f -o command.strace ls" ?

robinm@dwmsilpt433:/c/test_dir$ cat /proc/version
Linux version 4.19.128-microsoft-standard (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Tue Jun 23 12:58:10 UTC 2020
robinm@dwmsilpt433:/c/test_dir$ cmd.exe
command.strace  test_script.py
robinm@dwmsilpt433:/c/test_dir$ cmd.exe /c ver

Microsoft Windows [Version 10.0.18363.1316]
robinm@dwmsilpt433:/c/test_dir$ powershell.exe "Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntivirusProduct"

displayName              : Windows Defender
instanceGuid             : {D68DDC3A-831F-4fae-9E44-DA132C1ACF46}
pathToSignedProductExe   : windowsdefender://
pathToSignedReportingExe : %ProgramFiles%\Windows Defender\MsMpeng.exe
productState             : 393472
timestamp                : Mon, 09 Nov 2020 22:37:28 GMT
PSComputerName           :
robin865 commented 3 years ago

Also, I did manage to find this output from a time it failed:

robinm@dwmsilpt433:$ py.test -vvv some_dir1/some_dir2/test.py                                                                                                        Traceback (most recent call last):                                                                                                                                                                                                                                              File "/home/robinm/.pyenv/versions/2.7.18/bin/py.test", line 10, in <module>                                                                                                                                                                                                    sys.exit(main())
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/_pytest/config/__init__.py", line 58, in main
    config = _prepareconfig(args, plugins)
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/_pytest/config/__init__.py", line 196, in _prepareconfig                                                                                                                                                  pluginmanager=pluginmanager, args=args
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/pluggy/hooks.py", line 281, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/pluggy/manager.py", line 87, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/pluggy/callers.py", line 130, in _multicall
    gen.send(outcome)
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/_pytest/helpconfig.py", line 93, in pytest_cmdline_parse                                                                                                                                                  config = outcome.get_result()
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/pluggy/callers.py", line 81, in get_result                                                                                                                                                                _reraise(*ex)  # noqa                                                                                                                                                                                                                                                       File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/pluggy/callers.py", line 114, in _multicall
    res = hook_impl.function(*args)
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/_pytest/config/__init__.py", line 675, in pytest_cmdline_parse
    self.parse(args)
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/_pytest/config/__init__.py", line 845, in parse
    self._preparse(args, addopts=addopts)
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/_pytest/config/__init__.py", line 790, in _preparse
    self._initini(args)
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/_pytest/config/__init__.py", line 729, in _initini
    config=self,
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/_pytest/config/findpaths.py", line 104, in determine_setup
    dirs = get_dirs_from_args(args)
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/_pytest/config/findpaths.py", line 100, in get_dirs_from_args
    return [get_dir_from_path(path) for path in possible_paths if path.exists()]
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/_pytest/config/findpaths.py", line 97, in <genexpr>
    if not is_option(arg)
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/site-packages/py/_path/local.py", line 163, in __init__
    self.strpath = abspath(path)
  File "/home/robinm/.pyenv/versions/2.7.18/lib/python2.7/posixpath.py", line 371, in abspath
    cwd = os.getcwd()
OSError: [Errno 2] No such file or directory
therealkenc commented 3 years ago

@dorny can you also do:

$ powershell.exe "Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntivirusProduct"
dorny commented 3 years ago

@therealkenc here is the output:

powershell.exe "Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntivirusProduct"

displayName              : Windows Defender
instanceGuid             : {D68DDC3A-831F-4fae-9E44-DA132C1ACF46}
pathToSignedProductExe   : windowsdefender://
pathToSignedReportingExe : %ProgramFiles%\Windows Defender\MsMpeng.exe
productState             : 397568
timestamp                : Thu, 21 Jan 2021 19:51:20 GMT
PSComputerName           :

I'm running shell scripts which orchestrates build of .NET and node projects. Scripts run some git commands, run a docker container with SDK and bind mounted our source directory and basically that's it. Especially for git commands I'm sure they randomly stop working until I do the workaround with cd; cd -.

therealkenc commented 3 years ago

Thanks for the output. A like (thumbs up) on the OP is a good idea.

robin865 commented 3 years ago

So it happened again. I've attached strace when running "git diff" that hits this issue. I don't know that this was the command that caused it however.

strace_git_diff.txt

nick4fake commented 3 years ago

It has happened for me randomly with docker-compose. re-entering directory helped

nick4fake commented 3 years ago

After two days of testing in total it gets ridiculous - happens every 5-10 minutes on a brand new installation.

Provet commented 5 months ago

Hello! I'm facing the same issue and would like to know the current status. Any updates or resolution? Thank you. cc @craigloewen-msft

nmapx commented 2 months ago

Same, this bug should get some attention. In my case using Makefile targets for automation (which are switching directories a lot) cause a lot of trouble working on WSL. Doesn't happen on pure Linux / MacOS.

zstadler commented 1 month ago

This is very frustrating. It seems like this issue has been open and stale for more than 3.5 years now!

I'm using make to run a long series of tasks. Many times, make is "loosing" its current working directory and outputs this error:

make: getcwd: No such file or directory

Edit: The only temporary remedy I've found was to restart WSL by wsl --shutdown from windows followed by opening a new bash terminal. The above mentioned workarounds, using cd do not help here: even after using them, the make process is receiving the errors while it is running.

P.S., my version of the workaround is cd . or builtin cd . if you have an alias for cd, as I do.