code-server icon indicating copy to clipboard operation
code-server copied to clipboard

[Bug]: Memory leak?

Open aghasemi opened this issue 3 years ago • 28 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

OS/Web Information

  • Web Browser: Chrome
  • Local OS: macOS, ChromeOS
  • Remote OS: Ubuntu 20.04, 22.04
  • Remote Architecture: x86-64
  • code-server --version: 4.2.0, 4.3.0

Hi,

The memory consumed by the code-server (node) process gradually increases over time, regardless of whether and how the IDE is used. I have tested it multiple times and it has eventually used up all the 8GiB RAM of the server machine in a matter of 2 or so weeks.

Is this a well-known problem? Can I solve it permanently instead of rebooting the sever each time?

Many thanks

Steps to Reproduce

  1. Install code-server and run its daemon
  2. Continually measure memory usage of the process
  3. Wait :)

Expected

The memory usage should not be monotonically increasing

Actual

It is

Logs

No response

Screenshot/Video

No response

Does this issue happen in VS Code?

  • [X] I cannot reproduce this in VS Code.

Are you accessing code-server over HTTPS?

  • [X] I am using HTTPS.

Notes

No response

aghasemi avatar May 13 '22 08:05 aghasemi

I can confirm that the memory consumed by the code-server (node) process gradually increases over time.

benz0li avatar May 13 '22 13:05 benz0li

Does this also happen with native VS Code?

Side note: this would be a fun problem to solve. I'm not sure how, but I'm sure there are tools we could use to figure it out.

jsjoeio avatar May 13 '22 16:05 jsjoeio

Does this also happen with native VS Code?

No. I have VSCode continually open on a MacBook for weeks and never had a memory issue. Same for a ChromeOS device.

aghasemi avatar May 14 '22 18:05 aghasemi

I have the same / similiar problem on debian 11 with code server 4.4.0. Couldn't find the reason yet. When the memory is full, all sessions start to slow down, freeze and finally crash (Probably the memory leaking component / extension shuts down). Is there a way to pinpoint down this issue (Enable debug log as example)? I also thought to temporarily increase the Cloud Memory from 4GB to 8GB.

LaCocoRoco avatar May 23 '22 20:05 LaCocoRoco

I also thought to temporarily increase the Cloud Memory from 4GB to 8GB.

My "solution" was adding a line to crontab to restart code-server every 24 hours 😆

aghasemi avatar May 23 '22 20:05 aghasemi

Side note: this would be a fun problem to solve. I'm not sure how, but I'm sure there are tools we could use to figure it out.

https://www.npmjs.com/package/heapdump?

benz0li avatar May 24 '22 05:05 benz0li

Today the system used 3.4GB of 4GB. I killed the extension volar and it droped by 3GB. Once i also read about memory problems with the extension settings sync. Is there a way to limit the ram usage of installed extensions?

LaCocoRoco avatar May 25 '22 19:05 LaCocoRoco

Is there a way to limit the ram usage of installed extensions?

Not that I'm aware of. Found some things I'd read to look into it though:

  • https://medium.com/@krtirtho/make-visual-studio-code-less-ram-consuming-faster-90db8c76a187
  • https://stackoverflow.com/questions/53822808/visual-studio-code-took-10-7-gb-ram-usage-after-using-it-for-one-hour
  • https://www.paulhyunchong.com/posts/vscode-high-memory-usage
  • https://stackoverflow.com/questions/53658769/why-does-vs-code-require-so-much-memory-how-can-i-make-it-run-more-memory-effic

jsjoeio avatar May 25 '22 19:05 jsjoeio

@jsjoeio Thanks, i will look into it!

LaCocoRoco avatar May 25 '22 21:05 LaCocoRoco

I had issues with memory increasing, as multiple code-server instances would be open at once. Here is the issue: https://github.com/coder/code-server/issues/4351

It got solved by upgrading to a new version of code-server. Not sure if this is related but thought it was worth sharing.

Sharpz7 avatar Jun 01 '22 10:06 Sharpz7

I had issues with memory increasing, as multiple code-server instances would be open at once. Here is the issue: #4351

It got solved by upgrading to a new version of code-server. Not sure if this is related but thought it was worth sharing.

Thanks for sharing. I'm already on 4.4.0

aghasemi avatar Jun 03 '22 09:06 aghasemi

Have you tried messing with the extensions? That also produced a solution for me :))

On Fri, 3 Jun 2022, 10:02 Alireza Ghasemi, @.***> wrote:

I had issues with memory increasing, as multiple code-server instances would be open at once. Here is the issue: #4351 https://github.com/coder/code-server/issues/4351

It got solved by upgrading to a new version of code-server. Not sure if this is related but thought it was worth sharing.

Thanks for sharing. I'm already on 4.4.0

— Reply to this email directly, view it on GitHub https://github.com/coder/code-server/issues/5201#issuecomment-1145755581, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALCTWHSLGC5JZI2GGA7LM2TVNHC3LANCNFSM5V2ST4SQ . You are receiving this because you commented.Message ID: @.***>

Sharpz7 avatar Jun 03 '22 11:06 Sharpz7

I have the same problem on CentOS 8.4 with code-server 4.4.0. It is not determined which version introduced this problem,as far as I can tell,there is no problem with 3.12.0.

leeyzero avatar Jun 05 '22 02:06 leeyzero

Have you tried messing with the extensions? That also produced a solution for me :))

I'd rather wait for an official fix. But which extension? :D

aghasemi avatar Jun 05 '22 17:06 aghasemi

Have you tried messing with the extensions? That also produced a solution for me :))

I'd rather wait for an official fix. But which extension? :D

Volar Extension used about 700MB per instance in my case. It also felt like it did still run in the background after closing an workspace.

LaCocoRoco avatar Jun 06 '22 21:06 LaCocoRoco

I opened a large repo with many sub packages, and Memory Usage can be used almost 8G. When I just opened a sub package, Memory just 2G. So, code server will put every thing in workspace into memory?

Tzxhy avatar Jul 19 '23 08:07 Tzxhy

I do not believe it puts everything in memory. Also it should be restricted by Node's maximum memory limit, I think? Which by default is pretty low. Have you confirmed it is code-server using that memory? It could be a language server or something.

code-asher avatar Jul 19 '23 20:07 code-asher

Oh, sorry. I just found that the memory usage inside docker container and outside is not same, and the difference can be large. In container, use free -h get used + cached can be 7GB, but outside container, use docker stats containerID, show 1GB / 7GB.

Tzxhy avatar Jul 20 '23 02:07 Tzxhy

i'm having the same issue, i only have the following extensions installed: "docker", "dotenv", and "yaml". I just put a memory limitation in my docker container config and set up a cron job to restart the container every day.

Anaxagoras-bc avatar Jan 29 '24 17:01 Anaxagoras-bc