Solution:
Root Cause: Remote System Out-Of-Memory (OOM) Termination
VS Code Remote runs a full headless Node.js server (
vscode-server) on the target machine to handle language servers, file watchers, extension host processes, and debugging tools. On lightweight remote instances (such as AWS EC2 t2.micro or small VPS containers with <= 2 GB RAM), intensive language server indexing or compilation tasks exhaust system memory. The Linux Out-Of-Memory (OOM) killer intervenes and terminates the
node process running
vscode-server, killing the active SSH session.
# Diagnostic Verification:
Connect via standard terminal SSH and inspect system kernel logs for OOM termination events:
bash
sudo dmesg -T | grep -i -E 'oom|killed process'
Check system journal logs for VS Code server crashes:
bash
journalctl -u ssh -e | grep -i 'killed'
# Step-by-Step Fix:
1.
Limit Language Server and Extension RAM Footprint:
Open local VS Code settings (settings.json) and add performance caps for remote extension hosts: json
"remote.SSH.useExecServer": true,
"typescript.tsc.autoDetect": "off",
"git.autofetch": false,
"search.followSymlinks": false
2.
Enable or Expand Swap Space on Remote Host:
Create a 2 GB swap file on the remote server to absorb memory spikes: bash
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile swap swap defaults 0 0' | sudo tee -a /etc/fstab
3.
Clean Up Stale VS Code Server Binaries:
Delete bloated remote server installations to free up disk space and memory buffers: bash
rm -rf ~/.vscode-server/bin/*
# Prevention & Long-Term Monitoring:
Avoid installing excessive indexing extensions on remote instances with restricted resource limits.