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

Node.js and NPM network dramatically slow #7254

Open
2 tasks done
ecalcutin opened this issue Jul 31, 2021 · 47 comments
Open
2 tasks done

Node.js and NPM network dramatically slow #7254

ecalcutin opened this issue Jul 31, 2021 · 47 comments

Comments

@ecalcutin
Copy link

ecalcutin commented Jul 31, 2021

Windows Build Number

Windows 11 Pro 21H2 Build: 22000.100

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

Kernel version: 5.10.43

Distro Version

Ubuntu 20.04

Other Software

I have Ubuntu, Docker (v20.10.7), WSL 2 installed in my system.
I am using nvm with node.js (tried different versions still the same results)

Repro Steps

Cloned my fresh repo.
npm install - might pass and actually install.
Whenever I want to install an additional package - it might take forever to install.

Expected Behavior

Should run smoothly, without a long time-consuming.

Actual Behavior

I have dramatically slow network speed while working with Node.js and NPM.

  • Request made from Node.js app - randomly are slow, unstable, timeouts
  • npm install might take forever

I have to cancel and run npm install again, and if I am lucky - all packages will be installed, otherwise, I have to cancel and run again.
I am unsure why cache revalidation takes so much time
image

Diagnostic Logs

I ran npm install --verbose
Here 24 mins duration highlighted, so I just canceled.
image

@ssalbdivad
Copy link

I'm having the same issue as of today, really bizarre 🤷

@ecalcutin
Copy link
Author

I'm having the same issue as of today, really bizarre 🤷

If you somehow fix it, please reply in this thread. It really annoying issue..

@ssalbdivad
Copy link

If you somehow fix it, please reply in this thread. It really annoying issue..

Will do. I'm back on native Ubuntu for now since I can't reliably update my project's dependencies.

Would be great if someone on the WSL team could take a look given that whatever set of circumstances causes this to happen effectively blocks node development on WSL, which I assume is one of its most popular applications.

@ecalcutin
Copy link
Author

@ssalbdivad I have just reinstalled windows 10 (didn't go forward to insiders preview Win11).
I checked with wsl --status that I have Kernel version: 5.10.16 and there are no updates.

However, if I update to Windows 11 Preview, i might get Kernel version: 5.10.43 version. Could you please check if you have issues in that particalar kernel version?

@ssalbdivad
Copy link

@ecalcutin Can confirm I'm on 5.10.43.

@ecalcutin
Copy link
Author

@ecalcutin Can confirm I'm on 5.10.43.

So, looks like this issue happens on 5.10.43.
Since on 5.10.16 - IS ok.

Could you please tell, was you running WSL in windows 11 preview? Otherwise, how did you get such kernel version?

@ssalbdivad
Copy link

Yes, I'm on Windows 11.

@ecalcutin
Copy link
Author

Yes, I'm on Windows 11.

And to confirm, have you made kernel update manually? (wsl --update) after upgrading to windows 11 ?

@ssalbdivad
Copy link

I believe I tried to manually update wsl when I was setting up wslg. Not sure as to whether that actually resulted in any updates or if I was already on 5.10.43.

@ecalcutin
Copy link
Author

ecalcutin commented Aug 5, 2021

I believe I tried to manually update wsl when I was setting up wslg. Not sure as to whether that actually resulted in any updates or if I was already on 5.10.43.

Seems like the wsl --update you and me ran, updated kernel version to broken one.
Have you tried the #5452
Googling about to how downgrade kernel version - I found that.

If you are able to downgrade kernel version , and you doing get node issue , probably it's kernel issue.

@ssalbdivad
Copy link

Interesting, rollback brought me all the way back to 4.19.104, but I'm still having the same issue 🤨

@ecalcutin
Copy link
Author

ecalcutin commented Aug 5, 2021

Interesting, rollback brought me all the way back to 4.19.104, but I'm still having the same issue 🤨

That's strange. But I can confirm that Kernel Version 5.10.16 - IS ok. I am working on it right now. Maybe there exists a command to install a specific version of kernel =\

I am really want to use Windows 11. I'll reinstall and upgrade to 11, and will check if WSL works ok without manually updating the kernel. I'll post my status here

@ecalcutin
Copy link
Author

Interesting, rollback brought me all the way back to 4.19.104, but I'm still having the same issue 🤨

That's strange. But I can confirm that Kernel Version 5.10.16 - IS ok. I am working on it right now. Maybe there exists a command to install a specific version of kernel =\

I am really want to use Windows 11. I'll reinstall and upgrade to 11, and will check if WSL works ok without manually updating the kernel. I'll post my status here

Confirm, that rolling back to 5.10.16 won't fix the issue once you get it after the update.

@ecalcutin
Copy link
Author

I reinstalled windows 10. Did update to Windows 11 120 build. Considering the consequences, issue is not related to WSL 2 Kernel versions, but related to Win11 in general

@ssalbdivad
Copy link

That makes sense, although worth noting I have no problems installing the same dependencies from npm on Windows 11 natively (i.e. without WSL).

@ecalcutin
Copy link
Author

ecalcutin commented Aug 25, 2021

@ssalbdivad Hi,
Please try the following in your WSL

sudo rm /etc/resolv.conf
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
sudo chattr +i /etc/resolv.conf

Then reboot and check if it works for you :)
For me, it looks like solved. Did 4 reboots - works as expected.

@ecalcutin
Copy link
Author

Closing, due to solution.

@ssalbdivad Hi,
Please try the following in your WSL

sudo rm /etc/resolv.conf
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
sudo chattr +i /etc/resolv.conf

Then reboot and check if it works for you :)
For me, it looks like solved. Did 4 reboots - works as expected.

@speller
Copy link

speller commented Sep 10, 2021

I think that's a workaround but not a solution. because out-of-the-box WSL doesn't work as expected and requires manual manipulations.

@wstoettinger
Copy link

I have also run into that issue and I'm still on Win 10 with WSL2 on kernel version 5.10.16. The workaround with resolv.conf brakes all DNS resolving so this is not a solution.

@Maydara86
Copy link

This issue should be reopened, I'm having the same problem here on a fresh windows 11 pro install with wsl2 ubuntu kernel 5.10.16.
BTW the project is on "/home/[user]/Workspace/project" and when I use wget my internet speed does not throttle or freeze.

@craigloewen-msft
Copy link
Member

Reopening this to track this issue.

@bohdan-shulha
Copy link

Happened to me today on latest kernel. Luckily, the resolve.conf hack helped to resolve this issue.

I'm disappointed spending $2k+ on a Windows laptop instead of Mac.

PS C:\Users\Bohdan> wsl --update
Checking for updates...
No updates are available.
Kernel version: 5.10.60.1

@paul-vd
Copy link

paul-vd commented Mar 13, 2022

I have a similar issue with anything node-related, I tried installing a dist via nvm, on my native Linux it downloads in less than a few seconds, on WSL it takes extremely long and then any npm installs after that takes equally long:

time nvm install 14

Downloading and installing node v14.19.0...
Downloading https://nodejs.org/dist/v14.19.0/node-v14.19.0-linux-x64.tar.xz...
Computing checksum with sha256sum
Checksums matched!
Now using node v14.19.0 (npm v6.14.16)
Creating default alias: default -> 14 (-> v14.19.0)

real    9m17.621s
user    0m1.591s
sys     0m1.067s

time npm i -g vercel --verbose

Click to expand!

time npm i -g vercel --verbose
npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/node',
npm verb cli '/usr/bin/npm',
npm verb cli 'i',
npm verb cli '-g',
npm verb cli 'vercel',
npm verb cli '--verbose' ]
npm info using npm@6.14.4
npm info using node@v10.19.0
npm verb npm-session 08e605c0615f69f8
npm http fetch GET 304 https://registry.npmjs.org/vercel 1102ms (from cache)
npm timing stage:loadCurrentTree Completed in 1135ms
npm timing stage:loadIdealTree:cloneCurrentTree Completed in 0ms
npm timing stage:loadIdealTree:loadShrinkwrap Completed in 1ms
npm http fetch GET 200 https://registry.npmjs.org/@vercel%2fruby 15ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/@vercel%2fpython 16ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/@vercel%2fgo 18ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/@vercel%2fnode 23ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/update-notifier 127ms (from cache)
npm http fetch GET 304 https://registry.npmjs.org/@vercel%2fbuild-utils 1384ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/@vercel/go/-/go-1.3.0.tgz 56170ms
npm http fetch GET 200 https://registry.npmjs.org/ts-node 3255ms
npm http fetch GET 200 https://registry.npmjs.org/ts-node/-/ts-node-8.9.1.tgz 1057ms
npm timing stage:rollbackFailedOptional Completed in 1ms
npm timing stage:runTopLevelLifecycles Completed in 87456ms
npm WARN notsup Unsupported engine for vercel@24.0.0: wanted: {"node":">= 12"} (current: {"node":"10.19.0","npm":"6.14.4"})
npm WARN notsup Not compatible with your version of node/npm: vercel@24.0.0
npm verb notsup Not compatible with your version of node/npm: vercel@24.0.0
npm verb notsup Required: {"node":">= 12"}
npm verb notsup Actual: {"npm":"6.14.4","node":"10.19.0"}

npm verb type body-timeout
npm verb stack FetchError: Response timeout while trying to fetch https://registry.npmjs.org/typescript (over 30000ms)
npm verb stack at Timeout.setTimeout [as _onTimeout] (/usr/share/npm/node_modules/node-fetch-npm/src/body.js:189:16)
npm verb stack at ontimeout (timers.js:436:11)
npm verb stack at tryOnTimeout (timers.js:300:5)
npm verb stack at listOnTimeout (timers.js:263:5)
npm verb stack at Timer.processTimers (timers.js:223:10)
npm verb cwd /home/paul
npm verb Linux 5.10.60.1-microsoft-standard-WSL2
npm verb argv "/usr/bin/node" "/usr/bin/npm" "i" "-g" "vercel" "--verbose"
npm verb node v10.19.0
npm verb npm v6.14.4
npm ERR! Response timeout while trying to fetch https://registry.npmjs.org/typescript (over 30000ms)
npm verb exit [ 1, true ]
npm http fetch GET 200 https://registry.npmjs.org/typescript 120754ms
npm http fetch GET 200 https://registry.npmjs.org/@types%2fnode 141415ms
npm timing npm Completed in 198993ms

npm ERR! A complete log of this run can be found in:
npm ERR! /home/paul/.npm/_logs/2022-03-13T10_36_27_149Z-debug.log

real 3m19.446s
user 0m1.492s
sys 0m0.227s

Versions

This is a brand new installation of W11 that I just downloaded yesterday, I also tried to delete the ubuntu and then reinstall a new one thinking that I might have messed something up on the first go, but it results in the same issue.

winver.exe:

image

wsl --status:

Default Distribution: Ubuntu-20.04
Default Version: 2

Windows Subsystem for Linux was last updated on 3/12/2022
WSL automatic updates are on.

Kernel version: 5.10.60.1

cat /etc/os-release:

NAME="Ubuntu"
VERSION="20.04.4 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.4 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

speedtest using speedtest-cli in wsl :

Download: 754.34 Mbit/s
Upload: 150.59 Mbit/s

nvm -v

0.39.1

@Markus-ipse
Copy link

I'm having similar problems - I have a node server that acts as reverse proxy for various REST APIs and requests that usually takes ~300ms takes 30+ seconds when the node server is running in WSL :(

Using Windows 11 and Kernel version: 5.10.102.1

@chavokim
Copy link

I'm having similar problems too

@zonzujiro
Copy link

zonzujiro commented Jul 23, 2022

Same problems. Win 11

Node is unusable because of this, TBH

@grabofus
Copy link

grabofus commented Aug 2, 2022

It seem to have been an issue with too low MTU on my end.

List your interfaces from Windows:

netsh interface ipv4 show subinterfaces

Find the interface WSL is using, for me this was "vEthernet (WSL)", and my MTU defaulted to 576. (if it's higher for you it might be a different issue)

Set the MTU on the interface to match your main interface, for me it was 1500:

netsh interface ipv4 set subinterface "vEthernet (WSL)" mtu=1500 store=persistent

(and maybe do a wsl --shutdown?)

@Souhail-JAMHOUR
Copy link

Still facing the same issue, MTU set to 1500 and tried the previous solution to delete the resolv.conf

@impguard
Copy link

Same here. my setup process has been the same for WSL for the last two years, only recently on a new machine did I run into this issue. Simply running wget https://nodejs.org/dist/v18.12.1/node-v18.12.1.tar.gz will result in a download speed of ~100 KB/s. Downloading anything else from anywhere else nets me 100 MB/s.

On my local PC machine my downloads from anywhere are predictably fine, it seems to be a specific issue with node servers and WSL, which is an interaction that I'm really not really sure I understand. Tried different Ubuntu versions (20 vs. 22) to no success. The current resolutions offered currently don't seem to resolve anything, unless I'm applying them wrong - adjusted the resolv.conf and restarted Ubuntu a few times and my machine to no avail.

@AAfetisov
Copy link

im just trying to run an nmp test with jest. An empty test takes ~15s to complete...
dunno what to do. Its unusable for dev

@pmacmillan
Copy link

FWIW I've experienced this issue several times and had given up on it.

I tried both changing /etc/resolv.conf and using http instead of https as described here.

What worked for me was installing node inside WSL using n and adding the following to my ~/.bashrc file (within WSL)

export N_PREFIX=$HOME/.n
export PATH=$N_PREFIX/bin:$PATH

(note the order of the path where I place $N_PREFIX/bin before the path)

I had noticed that which npm was pointing to /mnt/c/Program Files/nodejs/npm... which led me to think it was running something on the windows side instead, which I assume adds some overhead when inside of WSL.

What I would add to the conversation here is: What do you get when you run which npm at the WSL bash
prompt? If you get something like /mnt/c/Program Files/nodejs/npm then try what I've described here.

@AAfetisov
Copy link

Yeah I fixed the problem with wsl/node similarly but forgot to post here, sorry. My node was already under wsl but my projects were on the windows part. That's why I had lags. Moved everything to wsl and lags vanished. Very strange though that this wsl-windows communication is so slow. I guess other lag issues might be due to hidden calls to windows part

@NeuralClone
Copy link

The only thing that fixed this for me was installing one of the preview builds of WSL. I don't remember which one specifically but it was several releases before the most recent.

I had Node installed inside WSL using n and that had no impact on its performance or network connectivity for me. which npm showed an npm inside WSL. I've never had it installed outside of it.

Everything was still painfully slow and timed out constantly. None of the other suggestions had worked.

I'm now running the most recent stable release and it seems to be fine in that as well.

@lucaoskaique
Copy link

The only thing that fixed this for me was installing one of the preview builds of WSL. I don't remember which one specifically but it was several releases before the most recent.

I had Node installed inside WSL using n and that had no impact on its performance or network connectivity for me. which npm showed an npm inside WSL. I've never had it installed outside of it.

Everything was still painfully slow and timed out constantly. None of the other suggestions had worked.

I'm now running the most recent stable release and it seems to be fine in that as well.

which version are you using right now?

@NeuralClone
Copy link

NeuralClone commented Jan 11, 2023

The only thing that fixed this for me was installing one of the preview builds of WSL. I don't remember which one specifically but it was several releases before the most recent.
I had Node installed inside WSL using n and that had no impact on its performance or network connectivity for me. which npm showed an npm inside WSL. I've never had it installed outside of it.
Everything was still painfully slow and timed out constantly. None of the other suggestions had worked.
I'm now running the most recent stable release and it seems to be fine in that as well.

which version are you using right now?

(Edited to include more information.)

wsl --version:

WSL version: 1.0.3.0
Kernel version: 5.15.79.1
WSLg version: 1.0.47
MSRDC version: 1.2.3575
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.1105

cat /etc/os-release:

PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

nvm -v:

0.39.1

npm -v:

6.14.17

node -v:

v14.20.0

@lucaoskaique
Copy link

lucaoskaique commented Jan 13, 2023

Yeah I fixed the problem with wsl/node similarly but forgot to post here, sorry. My node was already under wsl but my projects were on the windows part. That's why I had lags. Moved everything to wsl and lags vanished. Very strange though that this wsl-windows communication is so slow. I guess other lag issues might be due to hidden calls to windows part

how did you solve? i'm beggining to think the problem is with my network provider.
tried everything posted in here nothing seams to get better

@AAfetisov
Copy link

how did you solve? i'm beggining to think the problem is with my network provider.
tried everything posted in here nothing seams to get better

my projects were on windows partition (like in c:\sources\ folder), while my node was installed on wsl part. So when I did npm install, npm test, etc the node would start to lag tremendously. Just a couple of simple jest tests would take 5 seconds to complete. When I moved the folder with all my projects to the wsl part(~/sources/), the lags disappeared.

Another funny reason why your node may lag, it's when, for some strange reason, it's main source of files is set to some dead mirror. A friend of mine just had this problem.

@lucaoskaique
Copy link

how did you solve? i'm beggining to think the problem is with my network provider.
tried everything posted in here nothing seams to get better

my projects were on windows partition (like in c:\sources\ folder), while my node was installed on wsl part. So when I did npm install, npm test, etc the node would start to lag tremendously. Just a couple of simple jest tests would take 5 seconds to complete. When I moved the folder with all my projects to the wsl part(~/sources/), the lags disappeared.

Another funny reason why your node may lag, it's when, for some strange reason, it's main source of files is set to some dead mirror. A friend of mine just had this problem.

i've never had this problems before, all my projects were always installed inside wsl not on a mounted windows. When i use 4G from my phone everything works pretty fine

@gusnd
Copy link

gusnd commented Mar 30, 2023

I'm having the same issue here. I tried resetting anything I could relate to the network, allowed in Avast, etc

image
image

@gusnd
Copy link

gusnd commented Mar 30, 2023

Disabling IPv6 in the network adapter fixed instantly

@lucaoskaique
Copy link

had to format my desktop and did a clean windows install, everythings going pretty fine till now

@paul-vd
Copy link

paul-vd commented Apr 13, 2023

Disabling IPv6 in the network adapter fixed instantly

This fixed it for me as well.

@pho3nixf1re
Copy link

pho3nixf1re commented Jun 7, 2023

IPv6 was also the root cause for me as well. This answer resolved it for me without having to fully disable IPv6:
https://askubuntu.com/a/1200257

Instead of disabling IPv6 completely, you can instruct Ubuntu to prefer IPv4 connections to IPv6 by editing the precedence blocks in /etc/gai.conf.

Uncomment the last lines. Check that file has the next uncommented lines.

#For sites which prefer IPv4 connections change the last line to
precedence ::ffff:0:0/96 100
...
#    For sites which use site-local IPv4 addresses behind NAT there is
#    the problem that even if IPv4 addresses are preferred they do not
#    have the same scope and are therefore not sorted first.  To change
#    this use only these rules:
#
scopev4 ::ffff:169.254.0.0/112  2
scopev4 ::ffff:127.0.0.0/104    2
scopev4 ::ffff:0.0.0.0/96       14

These were the last 4 lines in the file.

@ashishamway
Copy link

ashishamway commented Jul 26, 2023

None of the above solution fixed my issue. all version, machines all are same for me as well. but solution did not work.
What solved my issue is I did checkout from ubuntu machine only and then running yarn/npm run so quickly. Earlier I was doing git clone inside windows folder and running yarn/npm command from ubuntu.

@vadimkantorov
Copy link

vadimkantorov commented Dec 13, 2023

same problem - npm install is painfully slow and takes hours on my WSLv1 (Ubuntu 22.04)+Win11 (Version 10.0.22621.2715) setup (using NTFS paths). On bare Linux instances, even on GitHub Actions runners, it takes seconds or minutes

i'll try disabling IPv6 to check if it helps

@ravisharmaa
Copy link

ravisharmaa commented Dec 16, 2023

In my case I did these, for an Existing project

  • Enable/Disable ipV6
  • remove package-lock.json and try again

The removal of package-lock worked like charm. :)

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