WSL icon indicating copy to clipboard operation
WSL copied to clipboard

WSL 2 session takes 40 seconds just to get to prompt

Open mchassy opened this issue 6 years ago • 55 comments

  • Windows build number: Version 2004 (OS Build 19035.1) with Ubuntu 18.04 WSL

  • What I'm doing and what's happening: open WSL 2 session using MobaXterm (same result when using bash.exe)

  • What's wrong / what should be happening instead: Using WSL 1, the session took a second or two to open. Now with WSL2, it take 40 seconds. I am attaching a screen recording which is about as exciting as watching paint dry.

MobaXterm 2019-12-06 13-57-23.mp4.zip

mchassy avatar Dec 06 '19 14:12 mchassy

u Better to use a VM with linux instead wsl2. It's the same thing

ilqvya avatar Dec 06 '19 15:12 ilqvya

Same issue here using Windows Terminal version 0.7.3291.0 Windows build 19035.1, Ubuntu 18.04 on WSL2

videorec_tmp.zip

stefankummer avatar Dec 06 '19 17:12 stefankummer

@mchassy and @stefankummer thank you both for the videos! To help troubleshoot this, could you both please look at doing these steps:

  • After you start WSL can you run the dmesg command, put the output into a Github gist and paste a link to it here?
  • If you install a new distribution like Debian as a WSL 2 distro, does the problem persist there as well?

craigloewen-msft avatar Dec 06 '19 18:12 craigloewen-msft

Hi Craig ... done for the week (I'm in the UK), but I will do that on Monday. I can check for another distro as well.

mchassy avatar Dec 06 '19 19:12 mchassy

I'm hitting similar issues, originally thought it may have been related to https://github.com/microsoft/WSL/issues/4498

My symptoms are similar - 30s+ to get a new prompt. I've reset my Ubuntu 18.04 environment several times to troubleshoot. In my case, I've also observed some interesting behavior based on how I launch into wsl, starting from a new Windows PowerShell instance:

  • wsl.exe or ubuntu1804: 39s to prompt, I land in /home/noel
  • wsl.exe followed immediately by Ctrl+C: instant prompt, none of my .bashrc has run, and I'm in /mnt/c/Users/noel
  • wsl -d Ubuntu-18.04 /bin/bash: 2s to prompt, .bashrc has run, I land in /mnt/c/Users/noel

The last case seems to rule out it being "my fault" for having an excessively slow bash profile, and is an acceptable workaround for the time being

dmesg logs in case it helps: https://gist.github.com/noelbundick/36d20fdf21b01838ce5a97df10c39dc9

Edit: I'm an Insiders slacker and am on Version 2004 (OS Build 19033.1)

noelbundick avatar Dec 06 '19 20:12 noelbundick

@mchassy and @stefankummer thank you both for the videos! To help troubleshoot this, could you both please look at doing these steps:

  • After you start WSL can you run the dmesg command, put the output into a Github gist and paste a link to it here?
  • If you install a new distribution like Debian as a WSL 2 distro, does the problem persist there as well?

Hi Craig,

dmesg here : https://gist.github.com/stefankummer/0b8645e2fc3ae6d36271a27d32622cf6

I installed a new distro (Debian) and the problem does not arise. Debian starts normally, but still not Ubuntu.

Regards

stefankummer avatar Dec 07 '19 07:12 stefankummer

If I do a fresh install ubuntu starts normally. After sudo apt update && sudo apt upgrade the slow startup starts. I have tracked it down to /etc/profile.d/wsl-integration.sh. Disabling the X11 server check reduces the delay to a second or two. Disabling the audio check as well gives an instant startup as expected.

geerteltink avatar Dec 07 '19 11:12 geerteltink

If I do a fresh install ubuntu starts normally. After sudo apt update && sudo apt upgrade the slow startup starts. I have tracked it down to /etc/profile.d/wsl-integration.sh. Disabling the X11 server check reduces the delay to a second or two. Disabling the audio check as well gives an instant startup as expected.

I can confirm this, after commenting out the checks for pulseaudio and x11, the startuptime is back to normal.

M-Kub avatar Dec 07 '19 21:12 M-Kub

If I do a fresh install ubuntu starts normally. After sudo apt update && sudo apt upgrade the slow startup starts. I have tracked it down to /etc/profile.d/wsl-integration.sh. Disabling the X11 server check reduces the delay to a second or two. Disabling the audio check as well gives an instant startup as expected.

I can also confirm. Noticed I was having long hanging times after running my update script. My steps: Ran sudo vim /etc/profile.d/wsl-integration.sh Edited it to look as so: https://i.imgur.com/hNGrCnF.png Now it is working as it did before updating.

ghost avatar Dec 08 '19 02:12 ghost

@nhuse9 Yes. Refer to your approach. The startup time is back to normal.

I inserted return on the first line. And tracked the execution time consumption.

λ wsl
wsl:1 ->
11:25:29

wsl:2 ->
11:25:29

wsl:3 detect WSL host: 192.168.208.1 ->
11:25:29

wsl:4 set display -> (33s)
11:26:02

wsl:5 set audio done -> (5s)
11:26:07

The reason may be related to the network. Commands executed cannot return results in a timely manner.

👉 Updated: If I turn off Windows Firewall, The startup time is back to normal. 😅

Further testing (Runs on WSL):

# WSL_HOST=192.168.208.1
awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null

# set DISPLAY if there is an X11 server running  (Key commend) 
$ time env DISPLAY=192.168.208.1:0 xvinfo

# set up audio if pulse server is reachable only via tcp  (Key commend) 
$ time env PULSE_SERVER=tcp:192.168.208.1 pactl info

Result:

(using $WSL_HOST and my Lan IP)

# WSL_HOST=192.168.208.1

# set DISPLAY if there is an X11 server running  (Key commend) 
$ time env DISPLAY=192.168.208.1:0 xvinfo
xvinfo:  Unable to open display 192.168.208.1:0

real    0m32.391s
user    0m0.001s
sys     0m0.000s

$ time env DISPLAY=<lan ip>:0 xvinfo
xvinfo:  Unable to open display <lan ip>:0

real    0m3.147s
user    0m0.002s
sys     0m0.000s

# set up audio if pulse server is reachable only via tcp  (Key commend) 
$ time env PULSE_SERVER=tcp:192.168.208.1 pactl info
Connection failure: Connection refused

real    0m5.010s
user    0m0.000s
sys     0m0.003s
$ time env PULSE_SERVER=tcp:<lan ip> pactl info
Connection failure: Connection refused

real    0m3.138s
user    0m0.003s
sys     0m0.000s

And

(using 127.0.0.1)

$ time env DISPLAY=127.0.0.1:0 xvinfo
xvinfo:  Unable to open display 127.0.0.1:0

real    0m0.003s
user    0m0.002s
sys     0m0.000s

$ time env PULSE_SERVER=tcp:127.0.0.1 pactl info
Connection failure: Connection refused

real    0m0.004s
user    0m0.003s
sys     0m0.000s

env:

# Microsoft Windows [版本 10.0.19033.1] 
# WSL version 2 - Ubuntu 18.04.3 LTS 
$ xvinfo -version
xvinfo 1.1.3
$ pactl --version
pactl 11.1
Compiled with libpulse 11.1.0
Linked with libpulse 11.1.0

junxy avatar Dec 08 '19 04:12 junxy

It's because of the network check, I think. Close the Windows Firewall will fix this problem. This is the dmesg output:

[ 0.570791] Adding 2097152k swap on /swap/file. Priority:-2 extents:1 across:2097152k [ 0.601659] FS-Cache: Duplicate cookie detected [ 0.601661] FS-Cache: O-cookie c=00000000fa5cc921 [p=00000000261177d3 fl=222 nc=0 na=1] [ 0.601661] FS-Cache: O-cookie d=000000005e9b151a n=00000000e917c7fe [ 0.601662] FS-Cache: O-key=[10] '34323934393337333338' [ 0.601664] FS-Cache: N-cookie c=000000001f062dbd [p=00000000261177d3 fl=2 nc=0 na=1] [ 0.601665] FS-Cache: N-cookie d=000000005e9b151a n=000000008ae87d6d [ 0.601665] FS-Cache: N-key=[10] '34323934393337333338' [ 0.606069] FS-Cache: Duplicate cookie detected [ 0.606072] FS-Cache: O-cookie c=0000000068d70691 [p=00000000261177d3 fl=222 nc=0 na=1] [ 0.606072] FS-Cache: O-cookie d=000000005e9b151a n=0000000082f3bb09 [ 0.606072] FS-Cache: O-key=[10] '34323934393337333339' [ 0.606075] FS-Cache: N-cookie c=0000000046c85068 [p=00000000261177d3 fl=2 nc=0 na=1] [ 0.606076] FS-Cache: N-cookie d=000000005e9b151a n=00000000cba492b9 [ 0.606076] FS-Cache: N-key=[10] '34323934393337333339' [ 0.608752] FS-Cache: Duplicate cookie detected [ 0.608754] FS-Cache: O-cookie c=0000000068d70691 [p=00000000261177d3 fl=222 nc=0 na=1] [ 0.608755] FS-Cache: O-cookie d=000000005e9b151a n=0000000082f3bb09 [ 0.608755] FS-Cache: O-key=[10] '34323934393337333339' [ 0.608758] FS-Cache: N-cookie c=0000000046c85068 [p=00000000261177d3 fl=2 nc=0 na=1] [ 0.608759] FS-Cache: N-cookie d=000000005e9b151a n=00000000f8d9280e [ 0.608759] FS-Cache: N-key=[10] '34323934393337333339' [ 1.291850] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready [ 49.108158] hv_balloon: Max. dynamic memory size: 6430 MB [ 61.514076] WSL2: Performing memory compaction. [ 107.009342] init: (118) ERROR: LogUsage:253: Could not find owner of socket 2 2222 15432 [ 122.519965] WSL2: Performing memory compaction. [ 3423.555836] WSL2: Performing memory compaction. [11584.876330] WSL2: Performing memory compaction. [16446.158393] WSL2: Performing memory compaction.

Sword-Destiny avatar Dec 09 '19 06:12 Sword-Destiny

If I do a fresh install ubuntu starts normally. After sudo apt update && sudo apt upgrade the slow startup starts. I have tracked it down to /etc/profile.d/wsl-integration.sh. Disabling the X11 server check reduces the delay to a second or two. Disabling the audio check as well gives an instant startup as expected.

I can also confirm. Noticed I was having long hanging times after running my update script. My steps: Ran sudo vim /etc/profile.d/wsl-integration.sh Edited it to look as so: https://i.imgur.com/hNGrCnF.png Now it is working as it did before updating.

I had the same issues, and disabling the firewall removed the issue. Editing /etc/profile.d/wsl-integration.sh, like the image, solved the issues without disabling the firewall.

rsletta avatar Dec 09 '19 08:12 rsletta

If I do a fresh install ubuntu starts normally. After sudo apt update && sudo apt upgrade the slow startup starts. I have tracked it down to /etc/profile.d/wsl-integration.sh. Disabling the X11 server check reduces the delay to a second or two. Disabling the audio check as well gives an instant startup as expected.

I can also confirm. Noticed I was having long hanging times after running my update script. My steps: Ran sudo vim /etc/profile.d/wsl-integration.sh Edited it to look as so: https://i.imgur.com/hNGrCnF.png Now it is working as it did before updating.

I had the same issues, and disabling the firewall removed the issue. Editing /etc/profile.d/wsl-integration.sh, like the image, solved the issues without disabling the firewall.

I can not access the URL “https://i.imgur.com/hNGrCnF.png”. Could you please copy the content of your "/etc/profile.d/wsl-integration.sh" after modified?

Sword-Destiny avatar Dec 09 '19 08:12 Sword-Destiny

@Sword-Destiny: See Gist at https://gist.github.com/rsletta/0b634d717dd812bfb841383ca91e4974

rsletta avatar Dec 09 '19 09:12 rsletta

@rsletta: I followed your advice and commented out the same sections as you did. I even commented out setting WSL_HOST=localhost because it just gets unset after the commands which have just been commented out. My session seems to work just fine without them. Could somebody explain what this script is actually trying to do, including the parts which remains active?

mchassy avatar Dec 09 '19 11:12 mchassy

@craigloewen-msft: Might someone from the team have time to shed some light onto this?

rsletta avatar Dec 09 '19 11:12 rsletta

The "wsl-integration.sh" file was added to WSL2 with the last update to "wslu" to detect if an X11Server or Pulseaudio is running. Here is the bugreport about WSL2 "not" checking for it. Now the question still is whats causing the delay for the prompt to appear when the system is running this checks.

M-Kub avatar Dec 09 '19 12:12 M-Kub

Thanks @M-Kub. So ...

  • Audio .... I don't care. I'm not using audio on my WSL.
  • X11 - I am using that, so what does that mean if I don't verify in that script?
  • There is also a first block that seems to be checking context of the WSL session (container, VM, etc) based on testing that, it sets WSL_HOST to a given IP, only to set it localhost immediately afterwards? Why bother?

mchassy avatar Dec 09 '19 12:12 mchassy

Actually, I just saw that the session tool I'm using (Xmobaterm) give you the IP of the Xserver. Given that my WSL install is stable, I simple set WSL_HOST to that IP without any tests or conditions. Session opens instantaneously.

This kind of script should not be running every time you run a session, rather it could be run at setup with the possibility to run it again as necessary.

mchassy avatar Dec 09 '19 13:12 mchassy

Yep this seems related to Xserver. https://twitter.com/rsletta/status/1203957912072273921?s=21

benhillis avatar Dec 09 '19 15:12 benhillis