Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSL 2 session takes 40 seconds just to get to prompt #4737

Closed
mchassy opened this issue Dec 6, 2019 · 55 comments
Closed

WSL 2 session takes 40 seconds just to get to prompt #4737

mchassy opened this issue Dec 6, 2019 · 55 comments

Comments

@mchassy
Copy link

mchassy commented Dec 6, 2019

  • 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

@ilqvya
Copy link

ilqvya commented Dec 6, 2019

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

@stefankummer
Copy link

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

videorec_tmp.zip

@craigloewen-msft
Copy link
Member

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

@mchassy
Copy link
Author

mchassy commented Dec 6, 2019

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.

@noelbundick
Copy link

noelbundick commented Dec 6, 2019

I'm hitting similar issues, originally thought it may have been related to #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)

@stefankummer
Copy link

@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

@geerteltink
Copy link

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.

@M-Kub
Copy link

M-Kub commented Dec 7, 2019

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.

@ghost
Copy link

ghost commented Dec 8, 2019

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.

@junxy
Copy link

junxy commented Dec 8, 2019

@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

@Sword-Destiny
Copy link

Sword-Destiny commented Dec 9, 2019

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.

@rsletta
Copy link

rsletta commented Dec 9, 2019

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.

@Sword-Destiny
Copy link

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?

@rsletta
Copy link

rsletta commented Dec 9, 2019

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

@mchassy
Copy link
Author

mchassy commented Dec 9, 2019

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

@rsletta
Copy link

rsletta commented Dec 9, 2019

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

@M-Kub
Copy link

M-Kub commented Dec 9, 2019

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.

@mchassy
Copy link
Author

mchassy commented Dec 9, 2019

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
Copy link
Author

mchassy commented Dec 9, 2019

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.

@benhillis
Copy link
Member

benhillis commented Dec 9, 2019

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

@mchassy
Copy link
Author

mchassy commented Dec 9, 2019

Ok ... I am closing the issue.
I am simply putting this into wsl_setup.sh

WSL_HOST=${WSL_HOST:-XX.XX.XXX.XX}
export DISPLAY=${WSL_HOST}:0
export LIBGL_ALWAYS_INDIRECT=1

Not the most elegant solution, but I shouldn't have to modify it until we get to WSL 3 ;-)

@rbalint
Copy link

rbalint commented Dec 10, 2019

This will be fixed soon in the wslu package: https://bugs.launchpad.net/ubuntu/+source/wslu/+bug/1855520

@rbalint
Copy link

rbalint commented Dec 12, 2019

The change causing the long delay on WSL2 has been reverted in Ubuntu yesterday thus it can be fixed now with apt update ; apt upgrade.
There is also an improved fix adding all detection with caching the results in the -proposed pocket.
The https://bugs.launchpad.net/ubuntu/+source/wslu/+bug/1855520 bug includes information on how to get that fix. Feedback is appreciated.

@wil93
Copy link

wil93 commented Dec 12, 2019

Upgrading the wslu package fixed it!

The solution as of today is to simply run:

sudo apt update
sudo apt dist-upgrade

EDIT: oops, too late

😄

@azeveco
Copy link

azeveco commented Mar 18, 2020

I'm still getting super slow times. I did the apt update and apt upgrade, rebooted, but nothing seems to work.

My Windows 10 Home Single Language is at build 2004 and after I enabled version 2, it got extremely slow.

@ketozhang
Copy link

ketozhang commented Apr 1, 2020

While this is tangentially related, the issue for me was ohmyzsh. Uninstalling ohmyzsh fixed the startup time and the prompt return time. Make sure to test your slow times using pure bash or zsh first to see if this is the root problem.

I found there was no need to comment out the Xserver and audio portion on /etc/profile.d/wsl-integration.sh. However, I did run sudo apt update && sudo apt upgrade.

EDIT: Slowness is back again.

@fabioods
Copy link

Hello guys I found a possible reason for the problem, in my case I have installed NVM (Node Version Manager) in WSL and when I comment the following lines in .zshrc

# export NVM_DIR = "$ HOME / .nvm"
# [-s "$ NVM_DIR / nvm.sh"] && \. "$ NVM_DIR / nvm.sh" # This loads nvm
# [-s "$ NVM_DIR / bash_completion"] && \. "$ NVM_DIR / bash_completion" # This loads nvm bash_completion

wsl starts instantly

To continue using NVM I found a possible solution here:
https://www.growingwiththeweb.com/2018/01/slow-nvm-init.html

@rsletta
Copy link

rsletta commented Apr 16, 2020

Hello guys I found a possible reason for the problem, in my case I have installed NVM (Node Version Manager) in WSL and when I comment the following lines in .zshrc

# export NVM_DIR = "$ HOME / .nvm"
# [-s "$ NVM_DIR / nvm.sh"] && \. "$ NVM_DIR / nvm.sh" # This loads nvm
# [-s "$ NVM_DIR / bash_completion"] && \. "$ NVM_DIR / bash_completion" # This loads nvm bash_completion

wsl starts instantly

To continue using NVM I found a possible solution here:
https://www.growingwiththeweb.com/2018/01/slow-nvm-init.html

I experienced slow startups again. Commented out my NVM path like you, and got instant startup. Seems like that's the culprit in my setup too.

@cbartondock
Copy link

For me the key was allow all of my x11 server (vcxsrv) apps through the defender firewall. Massive speedup.

@eknee
Copy link

eknee commented Jul 7, 2020

NVM was the culprit for me. Commenting out the lines you mentioned @rsletta solved my issue

# export NVM_DIR = "$ HOME / .nvm"
# [-s "$ NVM_DIR / nvm.sh"] && \. "$ NVM_DIR / nvm.sh" # This loads nvm
# [-s "$ NVM_DIR / bash_completion"] && \. "$ NVM_DIR / bash_completion" # This loads nvm bash_completion
wsl starts instantly

@2015xli
Copy link

2015xli commented Jul 14, 2020

The problem for me is the network connection due to "pactl info". I found that by opening another Ubuntu shell and "ps -axf". This problem never existed before I did a "apt dist-upgrade".

I avoid the problem by simply "cat /dev/null > /usr/share/wslu/wsl-integration.sh" to set it empty, since I don't see how it can be useful to me. And I set the DISPLAY and PULSE_SERVER in my profile file:

export HOST=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
export DISPLAY=$HOST:0
export PULSE_SERVER=tcp:$HOST

My X apps and music apps run fine.

@krehwell
Copy link

commenting the NVM in .bashrc starts my wsl instantly as the @fahds has mentioned

@shugaoye
Copy link

I found that it will be very slow after I run a X server. If I run it as mc -X, it can start immediately.

@geohadab
Copy link

Hello guys I found a possible reason for the problem, in my case I have installed NVM (Node Version Manager) in WSL and when I comment the following lines in .zshrc

# export NVM_DIR = "$ HOME / .nvm"
# [-s "$ NVM_DIR / nvm.sh"] && \. "$ NVM_DIR / nvm.sh" # This loads nvm
# [-s "$ NVM_DIR / bash_completion"] && \. "$ NVM_DIR / bash_completion" # This loads nvm bash_completion

wsl starts instantly

To continue using NVM I found a possible solution here:
https://www.growingwiththeweb.com/2018/01/slow-nvm-init.html

I can confirm that this solved the slowness I just commented the NVM

@ronilaukkarinen
Copy link

Thank you @fabioods! Only commenting out nvm from my .bashrc helped.

@NoSubstitute
Copy link

I found that it will be very slow after I run a X server. If I run it as mc -X, it can start immediately.

I too have had to start running mc that way.
The slowness of mc was driving me crazy!
It took several minutes to start, and then again if I use mcedit it took just as long to start it.

I didn't have to change the firewall (I tested opening firewall for ping, but it didn't help, so deactivated again).

@arafatx
Copy link

arafatx commented Aug 18, 2021

WSL 2 is a nightmare, I wasted many hours debugging and I thought that my bash script had trouble with linode API call which took more than a minute to call one API. In addition of that, WSL 2 did not display any of my beautiful spinning progress bar in terminal!. I tested the linode online API and I can confirm there was no issue with the API call. Then I tried the script on ubuntu virtualbox, the script ran very fast, with my beutiful spinning progress bar (that did not even show up in WSL2). Maybe WSL 2 is not suitable for bash script more than 15k lines which I tested this. Problem solved using multipass for ubuntu. I had to apologize to the linode team for getting mad with them because I thought there was a problem with their API.

@elliottcarlson
Copy link

After trying all of the suggestions in this thread (that comes up as the first result for most of my Google queries regarding WSL2 slowness), I finally found the culprit on my system to be Neofetch; starting any user shell would take upwards of a minute.

Commenting out the following lines in ~/.config/neofetch/config.conf solved the problem for me:

#    info "Resolution" resolution
#    info "DE" de
#    info "WM" wm
#    info "WM Theme" wm_theme
#    info "Theme" theme
#    info "Icons" icons

@xinxilas
Copy link

i dont have NVM
i dont have neofetch
I tried "cat /dev/null > /usr/share/wslu/wsl-integration.sh

Still having slowness at startup

And my windows explorer starts slows too because it tries to resolve shell $wsl/ directories

@NikolaDucak
Copy link

In my case, I had MegaCMD installed which added a custom bash completion script: /etc/bash-completion.d/megacmd_completion.sh. The culprit was this line in the said script, more precisely, the compgen -ca | grep mega- command. Removing the file or that for loop fixes the problem.

@geekshen8521
Copy link

geekshen8521 commented Sep 26, 2022

In my case, as soon as I remove the wslu from ubuntu 20.04 wsl, the terminal launch in 2 seconds.

@kierenfunk
Copy link

In my case, I had MegaCMD installed which added a custom bash completion script: /etc/bash-completion.d/megacmd_completion.sh. The culprit was this line in the said script, more precisely, the compgen -ca | grep mega- command. Removing the file or that for loop fixes the problem.

changing compgen -ca | grep mega- to compgen -ca mega- also works

@fathomserver
Copy link

For me it was commenting this line:

# Load Angular CLI autocompletion.
#source <(ng completion script)

Inside:
vim ~/.zshrc

In case this doesn't work out for you, go in that file and start commenting things you installed to find the culprit.

@indrajeetgour
Copy link

For me it was commenting this line:

# Load Angular CLI autocompletion.
#source <(ng completion script)

Inside: vim ~/.zshrc

In case this doesn't work out for you, go in that file and start commenting things you installed to find the culprit.

Worked for me too...

@dhruvinsh
Copy link

dhruvinsh commented Aug 8, 2023

For me, Microsoft Terminal take a while to open but once it open, next few time opening a split window or new tab of WSL works fine.

After a while if I try to open split it takes while as if the observer in the beginning.

But while using a Wezterm I do not observe such issue, first launch of wsl after fresh reboot is quick, and delayed new tab or split windows are faster as well.

looks like ldconfig is the issue,

[    3.198913] EXT4-fs (sdc): mounted filesystem with ordered data mode. Opts: discard,errors=remount-ro,data=ordered. Quota mode: none.
[   12.934813] /sbin/ldconfig:
[   12.934815] /usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link

@asolopovas
Copy link

asolopovas commented Oct 1, 2023

It is still slow on startup, each time when I spend some time in Windows and then start working on Linux, I forget how much faster it is than Windows. Because with WSL 2 Windows has spin up a virtual machine, and virtual machine started at boot time, I don't see any way WSL developers can decrease the boot time of WSL 2. They tried something really difficult with translating kernel calls from Linux with WSL 1, but it feels like it's abandoned, some posts mention that WSL 1 is not deprecated, but to be honest I never used it since WSL 2 came out just purely because it creates some uncomfortable edge case, so whatever solution you have most likely it will have a trade off that you will have to stick to. Maybe now with the power of AI, they will revisit the WSL 1 project?

@Luuk34
Copy link

Luuk34 commented Jan 9, 2024

Can anyone point to a good (good=WORKING) solution for this?

@lindhe
Copy link

lindhe commented Feb 7, 2024

looks like ldconfig is the issue,

@dhruvinsh Interesting! Did you find any fix? Can you please expand upon how you identified ldconfig as the culprit? I'm also having the issue with WSL2 being slow to spawn new terminal instances (often).

@dhruvinsh
Copy link

looks like ldconfig is the issue,

@dhruvinsh Interesting! Did you find any fix? Can you please expand upon how you identified ldconfig as the culprit? I'm also having the issue with WSL2 being slow to spawn new terminal instances (often).

I simply gave up.

I switched to wezterm and it works fine. Launch time is sub second (every time).

I do from time to time use he windows terminal and I do have the same lag, sometimes it takes 10 seconds to spawn a window/pane for wsl.

There is something different between how wezterm spawn the wsl vs Microsoft terminal.

@ahmedmustafamo
Copy link

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 great job. I've tried to do the same, but there's nothing on my /etc/profile.d/wsl-integration.sh file through my ubuntu wsl2. do you know the root cause for this issue?

@thecatontheflat
Copy link

Hello guys I found a possible reason for the problem, in my case I have installed NVM (Node Version Manager) in WSL and when I comment the following lines in .zshrc

# export NVM_DIR = "$ HOME / .nvm"
# [-s "$ NVM_DIR / nvm.sh"] && \. "$ NVM_DIR / nvm.sh" # This loads nvm
# [-s "$ NVM_DIR / bash_completion"] && \. "$ NVM_DIR / bash_completion" # This loads nvm bash_completion

wsl starts instantly

To continue using NVM I found a possible solution here: https://www.growingwiththeweb.com/2018/01/slow-nvm-init.html

This was the culprit for me too!

I believe that it started after installing one of the minor Windows updates. Interestingly, another symptom which may or may not be related is an overall slow DNS resolution when I open a URL in a browser for the first time.

@lindhe
Copy link

lindhe commented Jul 1, 2024

I too had issues caused by NVM. I'm not very knowledgeable at all about NVM – is this a bug in NVM or why does it cause such a bad effect? Or is it a WSL bug that makes NVM freak out?

@Luuk34
Copy link

Luuk34 commented Jul 13, 2024

A nice reference to get a working solution might be nice ....
I am trying to follow anything on this problem, for over a month now, and still not real solution ....

@UNCCristianMerino
Copy link

For me it was commenting this line:

# Load Angular CLI autocompletion.
#source <(ng completion script)

Inside: vim ~/.zshrc

In case this doesn't work out for you, go in that file and start commenting things you installed to find the culprit.

This worked for me! Thank you!

@mdrzn
Copy link

mdrzn commented Oct 8, 2024

In my case, I had MegaCMD installed which added a custom bash completion script: /etc/bash-completion.d/megacmd_completion.sh. The culprit was this line in the said script, more precisely, the compgen -ca | grep mega- command. Removing the file or that for loop fixes the problem.

This solved it for me, went from over 10s to load to 0s. This thread is so important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests