microsoft / WSL

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

interop hangs with long wslenv exports #4906

Closed sfullmer closed 9 months ago

sfullmer commented 4 years ago

Not a system crash (but can include minidump if that makes sense, please let me know).

Version: Microsoft Windows [Version 10.0.19041.84]

I am using the Ubuntu build with WSL 2. here is the info from wsl -l -v NAME STATE VERSION

The problem occurs with the WSL 2 / Ubuntu-18.04 instance (the running instance).

I'm attempting to set environment variables for use within cmd.exe when it is run from specific WSL 2 instances. Below is the export statements I'm using to generate the environment variables.

SAMPLE OF ENVIRONMENT VARS FOR WSL 2

export WindowsSDKLibVersion=10.0.16299.0
export WindowsSDKVersion=10.0.16299.0
export UCRTVersion=10.0.16299.0
export FrameworkVersion=v4.0.30319
export FrameworkVersion64=v4.0.30319
export VCToolsVersion=14.13.26128

export VCROOT='C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE'
export EXTROOT='C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs'
export FRMWRKROOT='C:\Windows\Microsoft.NET\Framework64'
export VSINSTALLDIR='C:\Program Files (x86)\Microsoft Visual Studio\2017\Community'
export MSVCTOOLROOT=$VSINSTALLDIR'\VC\Tools\MSVC\'$VCToolsVersion
export UniversalCRTSdkDir='C:\Program Files (x86)\Windows Kits\10'
export DOTNETFRMWRKROOT='C:\Windows\Microsoft.NET\Framework64\v4.0.30319'
export VSPERFTOOLS='C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools'
export WindowsSdkDir='C:\Program Files (x86)\Windows Kits\10'

export CommandPromptType=Native
export DevEnvDir=$VCROOT
export ExtensionSdkDir=$EXTROOT
export Framework40Version=v4.0
export FrameworkDir=$FRMWRKROOT
export FrameworkDir64=$FRMWRKROOT
export INCLUDE=$MSVCTOOLROOT'\ATLMFC\include'\;$MSVCTOOLROOT'\include'\;$UniversalCRTSdkDir'\include\'$WindowsSDKVersion'\ucrt'\;$UniversalCRTSdkDir'\include\'$WindowsSDKVersion'\shared'\;$UniversalCRTSdkDir'\include\'$WindowsSDKVersion'\um'\;$UniversalCRTSdkDir'\include\'$WindowsSDKVersion'\winrt'\;$UniversalCRTSdkDir'\include\'$WindowsSDKVersion'\cppwinrt'
export LIB=$MSVCTOOLROOT'\ATLMFC\lib\x64'\;$MSVCTOOLROOT'\lib\x64'\;$UniversalCRTSdkDir'\lib\'$WindowsSDKLibVersion'\ucrt\x64'\;$UniversalCRTSdkDir'\lib\'$WindowsSDKLibVersion'\um\x64'\;
export LIBPATH=$MSVCTOOLROOT'\ATLMFC\lib\x64'\;$MSVCTOOLROOT'\lib\x64'\;$MSVCTOOLROOT'\lib\x86\store\references'\;$UniversalCRTSdkDir'\UnionMetadata\'$WindowsSDKLibVersion\;#$UniversalCRTSdkDir'\References\'$WindowsSDKLibVersion\;$DOTNETFRMWRKROOT\;

export Platform=x64
export VCIDEInstallDir=$VSINSTALLDIR'\Common7\IDE\VC'
export VCINSTALLDIR=$VSINSTALLDIR'\VC'
export VCToolsInstallDir=$VSINSTALLDIR'\VC\Tools\MSVC\'$VCToolsVersion
export VCToolsRedistDir=$VSINSTALLDIR'\VC\Redist\MSVC\14.13.26020'
export VisualStudioVersion=15.0
export VS150COMNTOOLS=$VSINSTALLDIR'\Common7\Tools'
export VSCMD_ARG_app_plat=Desktop
export VSCMD_ARG_HOST_ARCH=x64
export VSCMD_ARG_TGT_ARCH=x64
export VSCMD_VER=15.6.7
export WindowsLibPath=$WindowsSdkDir'\UnionMetadata\'$WindowsSDKLibVersion\;$WindowsSdkDir'\References\'$WindowsSDKLibVersion
export WindowsSdkBinPath=$WindowsSdkDir'\bin'
export WindowsSdkVerBinPath=$WindowsSdkDir'\bin\'$WindowsSDKVersion
export __DOTNET_ADD_64BIT=1
export __DOTNET_PREFERRED_BITNESS=64

export WSLENV='WindowsSDKLibVersion:WindowsSDKVersion:UCRTVersion:FrameworkVersion:FrameworkVersion64:INCLUDE:LIB:LIBPATH:VCToolsVersion:VCROOT:EXTROOT:FRMWRKROOT:VSINSTALLDIR:MSVCTOOLROOT:UniversalCRTSdkDir:DOTNETFRMWRKROOT:VSPERFTOOLS:WindowsSdkDir:CommandPromptType:DevEnvDir:ExtensionSdkDir:Framework40Version:FrameworkDir:FrameworkDir64:Platform:VCIDEInstallDir:VCINSTALLDIR:VCToolsInstallDir:VCToolsRedistDir:VisualStudioVersion:VS150COMNTOOLS:VSCMD_ARG_app_plat:VSCMD_ARG_HOST_ARCH:VSCMD_ARG_TGT_ARCH:VSCMD_VER:WindowsLibPath:WindowsSdkBinPath:WindowsSdkVerBinPath:__DOTNET_ADD_64BIT:__DOTNET_PREFERRED_BITNESS'

END OF ENV VARS

If I execute cmd.exe after setting the environment vars above, cmd.exe will hang. I have to restart my WSL 2 instance in order to run cmd.exe again. This restart must happen even after setting the WSLENV to blank. If I reduce the amount of WSLENV variables, for example by removing LIBPATH, then cmd.exe will load and the included variables will be exposed.

To reiterate:

  1. Run a WSL 2 Ubuntu 18.04 instance
  2. Run the export statements listed above in the sample
  3. Execute cmd.exe and experience hang / crash of process.

NOTE: Command was aborted via kill -9 9038 from another WSL 2 command prompt.

9038  execve("/mnt/c/WINDOWS/system32/cmd.exe", ["cmd.exe"], 0x7ffd639f3148 /* 60 vars */) = 0
9038  arch_prctl(ARCH_SET_FS, 0x29c800) = 0
9038  set_tid_address(0x29c838)         = 9038
9038  brk(NULL)                         = 0x11e9000
9038  brk(0x11ea000)                    = 0x11ea000
9038  sched_getaffinity(0, 128, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]) = 32
9038  getpid()                          = 9038
9038  getcwd("/home/stuartf/bin", 4096) = 18
9038  uname({sysname="Linux", nodename="Foiegras", ...}) = 0
9038  getcwd("/home/stuartf/bin", 4096) = 18
9038  open("/mnt/c/WINDOWS/system32/cmd.exe", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_PATH) = 3
9038  readlink("/proc/self/fd/3", "/mnt/c/WINDOWS/system32/cmd.exe", 4095) = 31
9038  fstat(3, {st_mode=S_IFREG|0555, st_size=289792, ...}) = 0
9038  stat("/mnt/c/WINDOWS/system32/cmd.exe", {st_mode=S_IFREG|0555, st_size=289792, ...}) = 0
9038  close(3)                          = 0
9038  open("/proc/self/mountinfo", O_RDONLY) = 3
9038  readv(3, [{iov_base="", iov_len=0}, {iov_base="34 24 8:16 / / rw,relatime - ext"..., iov_len=1024}], 2) = 1024
9038  readv(3, [{iov_base="", iov_len=0}, {iov_base="de=755\n47 46 0:28 / /sys/fs/cgro"..., iov_len=1024}], 2) = 1024
9038  readv(3, [{iov_base="", iov_len=0}, {iov_base="group cgroup rw,net_prio\n58 46 0"..., iov_len=1024}], 2) = 787
9038  readv(3, [{iov_base="", iov_len=0}, {iov_base="", iov_len=1024}], 2) = 0
9038  close(3)                          = 0
9038  getcwd("/home/stuartf/bin", 4096) = 18
9038  open("/proc/self/mountinfo", O_RDONLY) = 3
9038  readv(3, [{iov_base="", iov_len=0}, {iov_base="34 24 8:16 / / rw,relatime - ext"..., iov_len=1024}], 2) = 1024
9038  readv(3, [{iov_base="", iov_len=0}, {iov_base="de=755\n47 46 0:28 / /sys/fs/cgro"..., iov_len=1024}], 2) = 1024
9038  readv(3, [{iov_base="", iov_len=0}, {iov_base="group cgroup rw,net_prio\n58 46 0"..., iov_len=1024}], 2) = 787
9038  readv(3, [{iov_base="", iov_len=0}, {iov_base="", iov_len=1024}], 2) = 0
9038  close(3)                          = 0
9038  brk(0x11eb000)                    = 0x11eb000
9038  brk(0x11ed000)                    = 0x11ed000
9038  ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
9038  ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
9038  ioctl(2, TCGETS, {B38400 opost isig icanon echo ...}) = 0
9038  ioctl(0, TIOCGPGRP, [9036])       = 0
9038  getpgid(0)                        = 9036
9038  fstat(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 4), ...}) = 0
9038  fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 4), ...}) = 0
9038  fstat(2, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 4), ...}) = 0
9038  ioctl(0, TIOCGWINSZ, {ws_row=66, ws_col=120, ws_xpixel=0, ws_ypixel=0}) = 0
9038  ioctl(0, SNDCTL_TMR_START or TCSETS, {B38400 -opost -isig -icanon -echo ...}) = 0
9038  dup(0)                            = 3
9038  socket(AF_VSOCK, SOCK_STREAM|SOCK_CLOEXEC, 0) = 4
9038  bind(4, {sa_family=AF_VSOCK, sa_data="\0\0\377\377\377\377\377\377\377\377\0\0\0\0"}, 16) = 0
9038  getsockname(4, {sa_family=AF_VSOCK, sa_data="\0\0s\4\0\0\377\377\377\377\0\0\0\0"}, [16]) = 0
9038  listen(4, 4)                      = 0
9038  socket(AF_UNIX, SOCK_SEQPACKET, 0) = 5
9038  connect(5, {sa_family=AF_UNIX, sun_path="/run/WSL/8966_interop"}, 110) = 0
9038  write(5, "\6\0\0\0\207\20\0\0s\4\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 4231) = 4231
9038  accept4(4,  <unfinished ...>)     = ?
9038  +++ killed by SIGKILL +++
Biswa96 commented 4 years ago

Could you use proper markdown syntaxes in your question please? The strace output and the commands are hardly readable.

sfullmer commented 4 years ago

Could you use proper markdown syntaxes in your question please? The strace output and the commands are hardly readable.

Interesting. It tells me at the bottom of the edit page "Styling with Markdown is supported", so I'm not sure what you're hoping for. The strace commands all start with PID and there's only one command to run. 'cmd.exe'. I'll see what I can do though. I'll try marking as code block.

sfullmer commented 4 years ago

Wow. I feel a bit silly. Even though I quoted the line from the edit, I kept adding a 'not' into this text: Styling with Markdown is supported. Many apologies if this appeared obtuse. Thanks for your suggestion Biswa96! If there's anything else I can add to improve the readability of the issue, please let me know. Cheers.

therealkenc commented 4 years ago

More straightforward repro:

$ export FOO=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$ export FOO=$FOO$FOO$FOO$FOO$FOO$FOO$FOO$FOO$FOO$FOO$FOO$FOO
$ export FOO=$FOO$FOO$FOO$FOO$FOO$FOO$FOO$FOO$FOO$FOO$FOO$FOO
$ export WSLENV=FOO
$ cmd.exe /c ver
# hangs here

[edit] More amusing screencap update after a wsl.exe --shutdown in another console. I mean, I wouldn't call the fail catastrophic. That seems a little exaggerated. :)

image

therealkenc commented 4 years ago

Failure mode a little different on 20236. At least it doesn't hang.

image

Biswa96 commented 4 years ago

At least it doesn't hang.

Internally, it timed out (ETIMEDOUT) after 10 seconds in poll(2). The environment parsing in LxssManager maybe related to this.

hacki11 commented 2 years ago

Can confirm, is there a workaround available?

i found a way but not that funny. For me i needed a PATH variable added from WSL to Windows.

export PATH_WSL=/mnt/c/somepath:/mnt/c/someotherpathexceedinglimits
export WSLENV=PATH_WSL/l
# then call the windows exe
cmd /V /c "set PATH=%PATH_WSL%;%PATH% && the_command"

How calling the commands struggles me, is there a possibility to hook this into some pre-windows-exe calls? Is it possible to somehow add a hook here: sudo echo ":WSLInterop:M::MZ::/init:" > /proc/sys/fs/binfmt_misc/register

https://stackoverflow.com/a/38920711/3342853

microsoft-github-policy-service[bot] commented 9 months ago

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!