WSL icon indicating copy to clipboard operation
WSL copied to clipboard

WSL2 automounted directories randomly stop working

Open robin865 opened this issue 4 years ago • 18 comments

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.

robin865 avatar Jan 19 '21 17:01 robin865

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.

dorny avatar Jan 21 '21 09:01 dorny

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.

therealkenc avatar Jan 22 '21 18:01 therealkenc

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).

robin865 avatar Jan 22 '21 18:01 robin865

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"

therealkenc avatar Jan 22 '21 19:01 therealkenc

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 avatar Jan 22 '21 21:01 robin865

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

robin865 avatar Jan 22 '21 21:01 robin865

@dorny can you also do:

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

therealkenc avatar Jan 22 '21 23:01 therealkenc

@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 -.

dorny avatar Jan 23 '21 09:01 dorny

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

therealkenc avatar Jan 25 '21 17:01 therealkenc

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

robin865 avatar Feb 19 '21 23:02 robin865

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

nick4fake avatar Mar 10 '21 14:03 nick4fake

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

nick4fake avatar Mar 11 '21 12:03 nick4fake

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

Provet avatar Jan 23 '24 00:01 Provet

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.

nmapx avatar Apr 17 '24 23:04 nmapx

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.

zstadler avatar May 28 '24 18:05 zstadler

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.

Same here..... I'm using WSL and encounter: Traceback (most recent call last): File "samcli/main.py", line 12, in File "click/core.py", line 1157, in call File "click/core.py", line 1078, in main File "click/core.py", line 1686, in invoke File "click/core.py", line 943, in make_context File "click/core.py", line 1408, in parse_args File "click/core.py", line 2400, in handle_parse_result File "click/core.py", line 2362, in process_value File "samcli/cli/cli_config_file.py", line 220, in configuration_callback FileNotFoundError: [Errno 2] No such file or directory [PYI-8461:ERROR] Failed to execute script 'main' due to unhandled exception!

I have to workaround just like what OP did and it temporarily fixed the issue. Super annoying and I thought I was doing something wrong on my end wasting my time finding it.

josephj1o4e1 avatar Sep 30 '24 07:09 josephj1o4e1

Just to report, this issue is still present. I have a Python script that creates and handles files in a folder, and eventually, os.getcwd() will fail when executing from a WSL2 environment. I have no workaround for this so far.

marcelogturing avatar Apr 08 '25 14:04 marcelogturing

+1

kire73 avatar May 29 '25 02:05 kire73

+1

CasDefibrion avatar Jul 03 '25 09:07 CasDefibrion

+1

mrheat avatar Jul 09 '25 13:07 mrheat