hassio-addons / addon-vscode

Studio Code Server - Home Assistant Community Add-ons
https://addons.community
MIT License
479 stars 81 forks source link

Apparent memory leak #565

Open ScottG489 opened 1 year ago

ScottG489 commented 1 year ago

Problem/Motivation

This addon increases in memory consumption until my system runs out.

Screen Shot 2023-01-11 at 5 50 17 PM

I've been monitoring it since my last incident and I had to restart the host. The host has a total of 4GB of memory which meets the documented requirements.

Though I've only been tracking memory per-addon for the duration of the first graph, I have been running this addon for over a year and I've only been having memory usage issues recently:

Screen Shot 2023-01-11 at 6 38 43 PM

I usually update addons pretty quickly after there's a release, and I can see v5.4.1 was released right around that time. Though from the release notes nothing sticks out.

I'm on the latest version and default config.

Expected behavior

For the memory usage of this addon to not increase indefinitely.

Actual behavior

Memory appears to increase indefinitely. Last time my system used up all memory and swap and locked up due to swap disk usage and I had to restart.

Steps to reproduce

As far as I can tell I'm using VS Code normally. I've only installed one extension (vim).

Unfortunately, I don't have any more information than above, but I'm happy to troubleshoot and get more information if you have suggestions on how to do so. I connected to the container and it doesn't have ps or even free so it seems like my tooling in the container is limited.

Thoughts on what this could be?

leowinterde commented 1 year ago

Same problem here.

limitless00net commented 1 year ago

Same problem here.

github-actions[bot] commented 1 year ago

There hasn't been any activity on this issue recently, so we clean up some of the older and inactive issues. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thanks!

JonathanVarild commented 1 year ago

Just updated my Home Assistant addons and started experiencing issues with my home "lagging". After investigating the issue, I noticed that the Visual Studio addon consumed 95% CPU and 57% ram. Turning the addon off lowered the overall resource usage on my Home Assistant system. See attached pictures.

Skärmavbild 2023-02-20 kl  19 29 49 Skärmavbild 2023-02-20 kl  19 29 25
ScottG489 commented 1 year ago

Still an issue.

doug-hoffman commented 1 year ago

I've also seen a memory leak...

image

image

I noticed that it started happening after I opened folder /, because I was going back and forth between editing a local addon and HA config. After switching back to /config and restarting vscode, I haven't seen the problem again.

BNolet commented 1 year ago

I specifically started configuring the Terminal & SSH addon to be able to use VSCode Remote - SSH specifically because of this memory issue.

My theory is that with each loading of the VSCode web interface, it's spinning up a new process without killing the old one. I say this because judging by the memory footprint over time, I can see stark stepwise jumps of memory use.

ScottG489 commented 1 year ago

@BNolet I've seen similar spike patterns as well and had also theorized that. I wonder if something changed recently with how new instances are being spun up.

I'm also considering using an external client, though I'll be using intellij instead. I've already got it working via sshfs.

VNRARA commented 1 year ago

Have any of you guys been experiencing random reboots because of this maybe? My HA install has been rebooting pretty frequently and couldn't find a culprit. I've started disabling add-ons and after I noticed (see #589 as well) VSS uses port 1337 which shows up a lot in the logs.

ScottG489 commented 1 year ago

@VNRARA I've had to manually reboot my system because I ran out of memory, and soon after swap. Once everything starts swapping to disk the system essentially locks up.

I'd suggest enabling resource usage sensors for your add-ons. I've found it very valuable since I've done so. You can do this by going to the services created for each add-on and enabling the CPU and memory percent sensors.

VNRARA commented 1 year ago

I think both Node-Red and VSCode might be culprits here. (I'm on a 4GB system)

image

VS code is already using: +100mb RAM from boot and Node-Red +115MB.

image image

This also sometimes happens:

image

[02:28:34] [172.30.32.2][c05a3361][ManagementConnection] Unknown reconnection token (never seen). [02:28:34] [172.30.32.2][e68f3661][ExtensionHostConnection] Unknown reconnection token (never seen). [02:34:01] [172.30.32.2][e9f8b661][ManagementConnection] New connection established. [02:34:03] [172.30.32.2][aa78680f][ExtensionHostConnection] New connection established. [02:34:03] [172.30.32.2][aa78680f][ExtensionHostConnection] <468> Launched Extension Host Process.

ScottG489 commented 1 year ago

I think a few hundred MB for either of those is more than acceptable.

Bringing this discussion back on topic though, I'd pay attention to sustained increases to the memory usage of VS Code as an indicator that you're also seeing a memory leak.

Xlinx64 commented 1 year ago

I have the same issue on my home assistant blue, after I disabled VSCode and didn’t use it anymore I didn’t have any reboots. When I used it heavily it crashed every half an hour.

VNRARA commented 1 year ago

Mine did crash so it may also be node-red

ScottG489 commented 1 year ago

@Xlinx64 Wow that's pretty bad if it happens so quickly. I'd double check the system requirements in the docs for this add-on to make sure your system meets them.

Also, here's an automation I created as a fallback to restart the add-on if it uses up too much memory. Be sure to change the value based on your system's resources:

trigger:
  - platform: numeric_state
    entity_id: sensor.studio_code_server_memory_percent
    above: 20
action:
  - service: hassio.addon_restart
    data:
      addon: a0d7b954_vscode
Xlinx64 commented 1 year ago

@ScottG489 Thank you for the script! But I dont dare to use the add-on until it is fixed. I use the File Editor add-on for now. I have to admit that on the day with the crashes I opened and closed it a lot since I did some template sensors.

BNolet commented 1 year ago

You can also use VSCode Remote - SSH with the SSH & Terminal add-on if you're looking for a longer term solution: https://community.home-assistant.io/t/vs-code-remote/129887/24?u=brandonnolet

boojew commented 1 year ago

Yea, I have the same issue on 16gb machine.. Takes about 1-2 weeks before I run out of memory :( Could be related to https://github.com/coder/code-server/issues/5201, but that is super vague.

github-actions[bot] commented 1 year ago

There hasn't been any activity on this issue recently, so we clean up some of the older and inactive issues. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thanks!

ScottG489 commented 1 year ago

Still an issue.

MiddleSiggy commented 1 year ago

I am having the same issue, I posted some more information in this ticket: https://github.com/coder/code-server/issues/6213

rbalaev commented 1 year ago

the same problem, until the complete loss of memory

le-clu commented 1 year ago

Same issue here. I keep VSCode off, and only switch it one when needed. Today I forgot to switch it off again and had to hard-reboot my Pi.

image

ScottG489 commented 1 year ago

If you'd like to help manage this for now, you can create an automation to restart the VSCode add-on if it uses up too much memory. Something like this (adjust the above number for your situation):

trigger:
  - platform: numeric_state
    entity_id: sensor.studio_code_server_memory_percent
    above: 20
action:
  - service: hassio.addon_restart
    data:
      addon: a0d7b954_vscode

Note that you'll need to enable the memory entity for this add-on in the supervisor integration.

github-actions[bot] commented 11 months ago

There hasn't been any activity on this issue recently, so we clean up some of the older and inactive issues. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thanks!

ScottG489 commented 11 months ago

Still an issue.

github-actions[bot] commented 10 months ago

There hasn't been any activity on this issue recently, so we clean up some of the older and inactive issues. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thanks!

ScottG489 commented 10 months ago

Still an issue.

mniewiera commented 10 months ago

I belive i have the same issue. Although i experience this problem longer then the creator of this issue. Haven't really payed attention to memory usage because i have quite a lot, but the cpu usage goes high like crazy. I noticed that after i only open vscode, i don't even have to open config.yml or some other file, and then go to a different page inside home assistant, after a while the fans of my home assistant nuc spin up like crazy. This never happens, only with this problem. On the addon page i see cpu values sometimes as low as 25% and sometimes as high as 75%. When i restart the addon everything becomes normal again. Cpu load and fan drops.

github-actions[bot] commented 9 months ago

There hasn't been any activity on this issue recently, so we clean up some of the older and inactive issues. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thanks!

ScottG489 commented 9 months ago

Still an issue.

mniewiera commented 9 months ago

Same here sadly

flaektrem commented 9 months ago

Same here. Please have a look at this

bobhogs commented 8 months ago

Same here

ScottG489 commented 8 months ago

FYI it's better form (this goes for anywhere you come across an issue on GitHub) to add a thumbs up to the original comment rather than posting a "me too" comment unless you have more info to add :+1:

mniewiera commented 8 months ago

FYI it's better form (this goes for anywhere you come across an issue on GitHub) to add a thumbs up to the original comment rather than posting a "me too" comment unless you have more info to add 👍

At least i know. I'm just preventing this issue to be closed due to inactivity ;-) And i guess the others are doing it for the same reason.

holdestmade commented 7 months ago

I've noticed also that if I use VSC installed in windows and access HA from there, the CPU and memory load rises again, so maybe its not the addon but the file access ? Currently having the addon stopped and using external, at least I remember to close that rather than stop the addon

fencing49 commented 7 months ago

Just wanted to pop in here and confirm that I am to getting massive memory leaks from this.

Just fired up my little nuc, 16gb ddr4 & 8 cores,

Absolutely ate all of that ram-up and about 93% of the CPU.

I'm running HAOS

Disabling the add-on significantly sped up everything within HA, it wasn't until I downloaded glance, did I notice how much it was eating.

Ftown14 commented 6 months ago

I have the same issue. Once I start VSC addon it will spike the CPU and then settle down once it gets all loaded. As soon as I go into VSC, with nothing more than the Welcome, no files open, and only the /config folder showing my CPU usage will go crazy, memory will keep climbing, do a small dump, climb higher than before dump, repeating this cycle as the memory usage increases. My Pi will shutdown from heat due to CPU usage going for 100-200%+ before the memory fills up. I have uninstalled and reinstalled. Just started in the past 2 weeks or so. So for now, I have it disabled and can't even start it.

ViezeVisNL commented 6 months ago

https://github.com/hassio-addons/addon-vscode/issues/761

Doesnt seem to have the full attention...

Ftown14 commented 6 months ago

Sadly, it seems like 0 attention as it is nearing a year old issue since reported. Funny though, as my issue only started within the last few weeks.

As with the suggestion in your issue thread, to disable when not using iznt viable for me. As when I start the VSC addon, it starts heating up the chipset on my pi until it shuts down/crashes (not sure which exactly) and I have to unplug my pi to reset it.

I'm currently looking for alternatives so I can work on my yaml's while away from my lan. I could just login to my VPN and sudo nano, but like the error checking to help double check my spacing and such.

PeeVv commented 5 months ago

Same here. Noticing an unusually high CPU usage on a near idle system, and it was VS Code using way too many resources:

Scherm­afbeelding 2024-01-13 om 21 04 56

You can clearly spot the moment I turned off the addon.

Ftown14 commented 4 months ago

Ok, so I think I figured out the cause, not sure if it is the addon or the specific extension that is causing it though.

First let me start off, I'm a Linux noob, I started maybe 6 months ago for my aquarium automation build, so if I say something dumb, please bare with me lol,

What I found out by using the 'top' command was 'node' was using a lot of CPU. Also, if I would leave the VSC instance, and go back, it would add another 'node' process. I tested this 3 times to verify, and each time it added another 'node' and would stack the CPU and Mem usage.

VS Issue

I used 'ps -Flww -p' with the PID at the end and it would show me a folder path to the .js file. I'm guessing this is the file that is being ran with node. Part of the path had the authors name, which allowed me to look at all the plugins that were enabled.

VS Issue 2

I looked through all the enabled extensions in VSC and came across...

VS Issue 3

Once I disabled and restarted VSC the issues when away. The CPU usage would go back to 0% for the Addon once I left the VSC screen. I reenabled this plugin again, restarted VSC and problem started again. So, disabled and now it works without issue, except the color formatting is gone and all the other features like autocomplete of entities. I also noticed that in extension marketplace it shows the version as 1.39, where as on the extensions GitHub it shows 1.40 being released last month. Granted nothing in the changelog that would hint the issue would be fixed though.

Again, I'm Linux dumb, so forgive me, but I'm guessing that means the Node command that is left running when you leave/disconnect from the VSC instance is not being shutdown and is running as a zombie. Hopefully there is a fix for this soon. I like VSC so much better than File Editor as I need all the help I can get with syntax errors.

github-actions[bot] commented 3 months ago

There hasn't been any activity on this issue recently, so we clean up some of the older and inactive issues. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thanks!

holdestmade commented 3 months ago

Still an issue for me

fribse commented 3 months ago

Still an issue here as well!

Maddjik commented 3 months ago

I am also having this problem in the last couple of weeks ! Cannot use vscode more than a couple minutes before it starts to misbehave and hang Haos. I dont know if this is related but node red wont start too and i had to delete it and reinstall. Running in a vm with 6gb ram and 2 cores x 2 threads (i9 9th gen)

Noirbonn666 commented 3 months ago

Ok, so I think I figured out the cause, not sure if it is the addon or the specific extension that is causing it though.

First let me start off, I'm a Linux noob, I started maybe 6 months ago for my aquarium automation build, so if I say something dumb, please bare with me lol,

What I found out by using the 'top' command was 'node' was using a lot of CPU. Also, if I would leave the VSC instance, and go back, it would add another 'node' process. I tested this 3 times to verify, and each time it added another 'node' and would stack the CPU and Mem usage.

VS Issue

I used 'ps -Flww -p' with the PID at the end and it would show me a folder path to the .js file. I'm guessing this is the file that is being ran with node. Part of the path had the authors name, which allowed me to look at all the plugins that were enabled.

VS Issue 2

I looked through all the enabled extensions in VSC and came across...

VS Issue 3

Once I disabled and restarted VSC the issues when away. The CPU usage would go back to 0% for the Addon once I left the VSC screen. I reenabled this plugin again, restarted VSC and problem started again. So, disabled and now it works without issue, except the color formatting is gone and all the other features like autocomplete of entities. I also noticed that in extension marketplace it shows the version as 1.39, where as on the extensions GitHub it shows 1.40 being released last month. Granted nothing in the changelog that would hint the issue would be fixed though.

Again, I'm Linux dumb, so forgive me, but I'm guessing that means the Node command that is left running when you leave/disconnect from the VSC instance is not being shutdown and is running as a zombie. Hopefully there is a fix for this soon. I like VSC so much better than File Editor as I need all the help I can get with syntax errors.

Definity solved the RAM and CPU Issue ...

Noirbonn666 commented 3 months ago

It may be more related to this issue here: https://github.com/keesschollaart81/vscode-home-assistant/issues/2656

github-actions[bot] commented 1 month ago

There hasn't been any activity on this issue recently, so we clean up some of the older and inactive issues. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thanks!