
Public Service Announcement: Visual Studio Code can kill remote machines…
I found this out the hard way.
I was using a Raspberry Pi (RPi) for a home project. It would slow down then die, seemly at random. A repower always fixed it.
The first thing I suspected was my Python code. I went down a deep dark rabbit hole trying to find the cause, included sending telemetry to a separate box running an ELK stack.
Looking at the telemetry visualisation, I had a lightbulb moment as it became clear that there was a 100% correlation between my code editor, Microsoft Visual Studio Code (VS Code) connecting to the RPi, and it suddenly running out of swap memory and becoming unresponsive.
VS Code was killing my little RPi. But correlation is not necessarily causation.

Figure 1 – Was VS Code attacking my RPi?[1]
The telemetry showed the RPi swap memory dropping to zero immediately after I did a remote connect to it with VS Code:

Figure 2 – Raspberry Pi dies after VS Code Connection
I searched cyberspace and found a post describing similar issues caused by the VS Code “TypeScript and Javascript Language Features” extension. I disabled that extension, but the issue persisted.
After more digging, I found an RPi forum topic with a reference to the other post. The Python extension was the culprit this time. That sounded promising as my code was Python.
I disabled the Python extensions and restarted VS Code and the RPi.

Figure 3 – The fix: disabling two Python extensions
I retested and the problem was solved:

Figure 4 – VS Code connected at 10:13, temporary spike in CPU and small drop in swap memory
Reenabled the Python and Python Debugger extensions in VS Code caused the problem to come back, so for me the issue is reproducible.
Disabling the Python extensions hasn’t caused me any issues as I wasn’t using the features, such as debugging. I just need a tool for editing my code remotely.
Why this happened
The VS Code “Remote – SSH” extension is super-convenient, but I hadn’t bothered to dig into how it works.
My assumption was that VS Code used SSH to connect to the remote machine and all the heavy lifting was done on the client side:

Figure 5 – Wrong: how I assumed VS Code “Remote – SSH” was architected
As with a lot of assumptions, this was wrong. Here is what it actually does[2]:

Figure 6 – VS Code “Remote – SSH” architecture: What really happens
Note the blue boxes on the remote machine. This is a heavy install that spins up node.js to run extensions and other code. The resource utilisation is more that you would be expecting if you were only thinking it was an SSH connection that lived off the land on the remote machine.
Extensions run on the remote machine. Disabling these extensions in VS Code reduced the memory usage on my RPi to an acceptable level.
To be fair, the in-app documentation for the “Remote – SSH” extension (which I hadn’t read) says the remote machine needs (among other things) a whole heap of RAM.

Figure 7 – The VS Code “Remote – SSH” extension needs a whole heap of RAM on the remote machine…
My little RPi has a paltry 512MB of RAM, so it is under the supported spec, and by all accounts it shouldn’t even work! Also, it runs an ARM CPU, and the documentation says support for this is limited.
I think the “Remote – SSH” extension should issue a warning if the remote machine is not up to spec.
Wrapping it up
VS Code is a useful and free code editing tool for developers. Use the “Remote – SSH” extension with caution. It requires significant resources (CPU, memory) on the remote machine and can cause impact to system performance.

Figure 8 – Public Service Announcement [3]
Never ever use VS Code to remote SSH to a production server (not that you would of course!).
PSA over.
[1] Image generated on Google Image FX with prompt “A stylised cartoon image of a big aggressive microsoft vscode blue icon attacks a small raspberry pi computer”
[2] VS Code Server architecture used on remote machines: https://code.visualstudio.com/docs/remote/vscode-server
[3] Image generated on Google Image FX with prompt “vintage Public Service Announcement poster on a brick wall that says “VSCode remotes need RAM””
thank you
LikeLike
VS Code Remote SSH: "Just a simple text editor over SSH!"
Also VS Code Remote SSH: *Spawns entire Node.js runtime, 47 extensions, TypeScript language server, and enough RAM usage to accidentally DoS your Pi*
The "simple" tools are never simple.
LikeLiked by 1 person
Remote Reply
Original Comment URL
Your Profile