26

Please read: See the last bit. I don't believe this is an issue related to Ubuntu, but rather VS Code.

Recently, under 17.10 and 18.04 (I just upgraded today), Ubuntu will randomly and completely freeze. I cannot move the cursor or use the keyboard. Naturally, I have tried switching to a TTY session with no success. Every time, I must resort to SysRq + REISUB, which is (obviously) not preferred.

I have attempted to switch graphics drivers, on the theory that it may be that. I was originally using the open source nVidia driver, and switched to the proprietary to no avail. I'm currently using the open source driver.

All that I typically have open is Firefox (not a ton of tabs loaded) and VS Code, with at most a couple files and a terminal open.

Any ideas?

Update: The system logs show no indication of anything at all happening, let alone something wrong. I don't know if this is related, but sometimes (and especially after booting) programs take a significant amount of time (> 5-10 seconds), even command line programs.

Yet another update! — Even with all GNOME extensions disabled, it still crashed. I tried XFCE, which still crashed.

Summary: Ubuntu completely freezes at seemingly random times, leaving no trace in logs, and is not related to any specific desktop environment or GNOME extensions.

(likely final) update: I'm convinced this is an issue with VS Code. I have been running GNOME for days, with other Electron apps open (Slack, Pulse, etc.), and have not had a single freeze. I have DM'd VS Code on Twitter, and will likely file a bug report as they haven't responded yet.

jhpratt
  • 622
  • 1
    Start with your logs. That's much easier than mucking with video drivers. – user535733 Jul 01 '18 at 01:59
  • @user535733 Which log specifically? – jhpratt Jul 01 '18 at 02:00
  • Hi jhpratt, for me worked this https://askubuntu.com/a/870235/790920. – abu_bua Jul 01 '18 at 02:02
  • @jhpratt I suggest methodically searching ALL your logs in /var/log. It should be apparent pretty quickly which ones are relevant and which ones not. You are, of course, searching for the few seconds before a freeze occurs, not just tediously reading everything...so it helps if you keep track of EXACT time of an incident. – user535733 Jul 01 '18 at 02:06
  • Nothing unexpected in the logs from the most recent crash. Just 'starting terminal' and stuff like that, which is naturally the kind of thing I'd be doing. – jhpratt Jul 01 '18 at 02:13
  • 1
    journalctl -b -1 -xe will show you logs at the end of the previous boot. How much RAM do you have? How much swap? free;swapon will tell you. – waltinator Jul 01 '18 at 03:04
  • @waltinator In the final seconds in the log provided, there is only one item, a discarded touch jump (which certainly wouldn't case a crash). I have 8 GB each of RAM and swap. – jhpratt Jul 01 '18 at 03:08
  • Have you installed any GNOME extensions? If so, good chance that may be your problem. Edit your question to include a list of installed extensions and I'll take a look for you. Report back to @heynnema. – heynnema Jul 01 '18 at 14:36
  • @heynnema Added! More active on SO, so I'm quite familiar with how things work. – jhpratt Jul 01 '18 at 21:50
  • I don't know what "SO" means. I don't see any extensions that stand out as known bad. But... turn them all off, and see if app launch times improve, and if the freezes stop. If it's better, then enable one extension at a time to find out which one is causing your problem. Report back. – heynnema Jul 02 '18 at 00:26
  • @heynnema Just disabled them all. We'll see what happens; sometimes it takes ~15 minutes, sometimes days, so who knows. (and SO → Stack Overflow) – jhpratt Jul 02 '18 at 00:46
  • @jhpratt What kernel version are you running now? (run uname -r to discover) Reboot, go to grub's Advanced Options menu and pick a kernel prior to July 1 update. Does problem persist? Have you changed startup applications to run xkbindkeys or something similar that hooks into Xorg input events? – WinEunuuchs2Unix Jul 07 '18 at 00:47
  • @WinEunuuchs2Unix Have you read the end of the post? I'll add a bit at the beginning to make it clearer. – jhpratt Jul 07 '18 at 00:48
  • @jhpratt Can you change the title to 'vscode' update causes Ubuntu 17.10 / 18.04 to lag Was this confirmed by temporarily removing / deactivating vscode? – WinEunuuchs2Unix Jul 07 '18 at 00:50
  • I haven't run VS Code in a couple days, in which time it would've crashed a few times at least. I'm convinced! – jhpratt Jul 07 '18 at 00:51
  • Can you install the version of vscode you were using prior to July 1 and pin it? – WinEunuuchs2Unix Jul 07 '18 at 00:52
  • Eh, I could, but then I don't have all the super cool features! Like I said, I intend on filing a bug report if they don't respond relatively soon. Not to mention I have no idea what version it broke on, as it was a little bit before the first as well. – jhpratt Jul 07 '18 at 00:52
  • I have the same problem with this editor. When I try import HttpClient in Angular app (alt + enter), app stucks and I should restart Ubuntu. – Kamil Naja Jan 19 '20 at 14:05

14 Answers14

17

So it turns out that this isn't specific to Ubuntu, but I'll post this here anyways for future reference.

Apparently, even though I'm ignoring certain files using the files.exclude setting (notably the ./node_modules directory), VS Code still watches those files for changes.

To solve that, simply copy the list from files.exclude to files.watcherExclude. This will prevent VS Code from searching the many thousands of files that are in node_modules or other similar directories. That way, it will leave some RAM for Chrome to gobble up.

jhpratt
  • 622
  • hi @jhpratt are these changes you're referring to changes to be made in VS Code's settings.json file? – cryanbhu Jul 22 '19 at 06:48
  • 1
    @cryanbhu Yes, that's correct. To the best of my knowledge, this information is still accurate as well. – jhpratt Jul 22 '19 at 08:45
  • 2
    I can see that node_modules is under watcherExclude but I am still facing the same issue. – Mohammad Faisal Oct 26 '19 at 16:36
  • **/.git/objects/**, **/.git/subtree-cache/**, and **/node_modules/** are included by default in files.watcherExclude – noraj Mar 17 '20 at 22:17
5

I just ran into this. Upon launch, in a big project, my system would freeze after ~20 seconds and become unresponsive (Ubuntu 18.04). Running htop while launching VSCode showed that it took all the cores to 100% (i7-8700K), ate all the memory (16gb) and then the swap. The freeze happened moments later. This was happening because of a bad extension, in my case it was CSS Peek.

So try launching vscode with extensions disabled (code --disable-extensions) and see if it still happens. If it doesn't track down the faulty extension and send it to hell.

I had random full freezes happening and spent quite a few hours trying to find out why. On restart the logs were really not helpful. I initially thought it was the nvidia driver, but no - just a VSCode extension.

5

I got the same issue in my Ubuntu 16.04.

I did switch off git.autorefresh in the Settings, then it works flawlessly and smoothly

Kumar KS
  • 151
3

I've experienced the same problem. Eventually I realized that in my case the problem is running out of memory (I have 8gb ram and just 1gb swap partition on disk). I fixed this by allocating additional swap space using file in my root directory:

sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

this will temporary enable additional 8gb of swap for your system. If it will help, here you can read further instructions for enabling new swap constantly.

Another options are: add RAM physically or add/enlarge swap partition.

I used new swap as a file because I got luks+lvm encrypted system and resizing existing swap partition is too complicated and risky in my case.

P.S. I got Ubuntu 18.04

Artem S.
  • 141
  • 3
2

I had the same issue. To fix this for a particular project you will want to update the .vscode/settings.json to look something like this:

{
  "python.pythonPath": "/usr/bin/python3",
  "files.exclude": {
    "**/.git": true,
    "**/.svn": true,
    "**/.hg": true,
    "**/CVS": true,
    "**/.DS_Store": true,
    "**/node_modules": true,
    "**/.firebase": true
  },
  "files.watcherExclude": {
    "**/.git/objects/**": true,
    "**/.git/subtree-cache/**": true,
    "**/node_modules/**": true
  }
}
2

For me, disabling gpu when calling vscode solved the problem.

Do it by using this alias to open vscode:

alias code='code --disable-gpu'
nemoo
  • 121
1

I have also suffered from random system crashes when running VSC. Even tried to start without extensions, which didn't help me at all. A few times my system froze right on startup of VSC.

However, I checked the logs and found that these crashes might correlate to the graphics driver (NVidia GTX 660).

Solution in my case: Switching from Nouveau to proprietary driver (I have chosen the metapackage)

Btw: Using Ubuntu 18.04

abu_bua
  • 10,783
gordon
  • 11
1

Download VSCode and extract it. You'll see a file name “code” in the folder. Open a terminal and navigvate to that folder. Enter the command

./code --disable-gpu

via phero_constructs on reddit

Also, see this issue comments. You can do CTRL+SHIFT+P, then find Preferences Configuration. Insert this into the json (don't forget to add a comma after the preceding entry):

"disable-hardware-acceleration": true
0

I had tried above workarounds and no luck.

For me, set the intel_idle.max_cstate=1 parameter in grub worked perfectly.

sudo cp /etc/default/grub /etc/default/grub.backup
sudo nano /etc/default/grub
# find the line begin with GRUB_CMDLINE_LINUX_DEFAULT
# append intel_idle.max_cstate=1 to original parameters.
sudo update-grub

reboot it.

Sam Shaw
  • 101
  • 1
0

For me following workaround worked

Open the Command Palette (Ctrl+Shift+P). Run the Preferences: Configure Runtime Arguments command. This command will open a argv.json file to configure runtime arguments. You might see some default arguments there already. Add "disable-hardware-acceleration": true Restart VS Code.

Lem
  • 101
0

After some recent vscode update I came across the same issue, tried almost everything except increasing Swap area but none seemed to work. The reason was vscode plugin eating up 80% of the RAM inside. The interesting part was this extension was not even showing up in vscode. Next time you open vscode keep a terminal handy and use this command to monitor the RAM usage.

free -m

When you see a very low available RAM then just type this command.

ps -aux

Now just check for the process that is eating most percent of your RAM. For me it was gopls plugin for golang. I just deleted the binary related to this process as its location was also clearly given by above command and restarted vscode. This solved the issue.

P.S I'm using Ubuntu 18.04 LTS

0

For me it was happening because of this extension Laravel Extra Intellisense, Even though i would start with --disable-extensions it didn't work i had to uninstall it

0

If you use cmake from VS Code, it uses all processors and then GUI frezees. You must decrease number of processor usage like below:

  1. Enter file>preference>settings at VS Code
  2. Search cmake.parallelJobs at settings panel search
  3. Set cmake.parallelJobs to a value less than nproc

Note: You can find number of processing units using "nproc" command at terminal.

0

I tried at least a half-dozen "fixes" for this issue, found on this forum and elsewhere. None helped. Except this: vscode-openfile-dialog-opens-in-background

I'm using Gnome 45.4 on Fedora workstation 39 with a 6.7.4-200 kernel. I tried everything, but the article below was the only thing that fixed it. I could not see the dialog open in the background, could not find it, could not switch to it.

The advice is to go to settings -> file dialog -> click simple dialog enable, or other said Files -> Simple Dialog = true

GOOD LUCK finding that setting, especially if you're new to VSCode, like I am. I goofed around with it for a while before turning to the ultimately effective solution to my case: installing the gnome extension "Grand Theft Focus" to focus dialog windows for Visual Studio Code.

GrandTheftFocus

It just works.