Repository navigation
Description
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version: 1.135.0 (
08d4889f9ec4a1685d257b9b95de036c8e1ce1e5, x64) - OS Version: Linux in Docker, with Tini as PID 1
This leak has been observed for a long time across multiple VS Code versions and is still present after updating to 1.135.0.
Steps to Reproduce:
- Start
code serve-web, connect once, then disconnect all clients. - Wait for the one-hour idle timeout and connect again.
After reconnecting, the previous server-main.js remains alive under PID 1 while serve-web starts a new instance:
tini
├── code serve-web
│ └── sh bin/code-server
│ └── node out/server-main.js # new
└── node out/server-main.js # old, PPID 1
Possibly relevant code: serve-web starts the server with new_script_command() and calls child.kill() when the idle timeout is reached:
vscode/cli/src/commands/serve_web.rs
Lines 823 to 833 in 08d4889
| async fn start_version(args: StartArgs, path: PathBuf) { | |
| info!(args.log, "Starting server {}", args.release.commit); | |
| let executable = path | |
| .join("bin") | |
| .join(args.release.quality.server_entrypoint()); | |
| let socket_path = get_socket_name(); | |
| let mut cmd = new_script_command(&executable); | |
| cmd.stdin(std::process::Stdio::null()); |
vscode/cli/src/commands/serve_web.rs
Lines 923 to 928 in 08d4889
| } | |
| _ = &mut kill_timer => { | |
| info!(args.log, "[{} process]: idle timeout reached, ending", commit_prefix); | |
| let _ = child.kill().await; | |
| break; | |
| } |
For comparison, #319516 reported a similar leaked server process in the agent-host path, and #320631 changed that path to use kill_tree():
vscode/cli/src/tunnels/agent_host.rs
Lines 578 to 590 in 08d4889
| /// Kills the currently running server, if any. | |
| /// | |
| /// The server is launched via a bash/cmd shim (`<server>/bin/code-server-<quality>`) | |
| /// which `spawn`s the underlying `node ... server-main.js` child. A plain | |
| /// `child.kill()` only terminates the shim and reparents the node child to | |
| /// PID 1, leaking it. `kill_tree` signals the shim and its descendants so | |
| /// the node process is reaped along with the launcher. See issue #319516. | |
| pub async fn kill_running_server(&self) { | |
| let mut running = self.running.lock().await; | |
| if let Some(mut server) = running.take() { | |
| if let Some(pid) = server.child.id() { | |
| let _ = kill_tree(pid).await; | |
| } |
Expected: the idle timeout should stop the server completely, without leaving an old server-main.js process under PID 1. Could the serve-web shutdown path be missing the process-tree handling added for the agent-host path?
Activity
[-]code serve-web leaves orphaned server-main.js processes after idle timeout[/-][+]C ode serve-web leaves orphaned server-main.js processes after idle timeout[/+][-]C ode serve-web leaves orphaned server-main.js processes after idle timeout[/-][+]VSCode server LEAKs server-main.js process.[/+]Kidsunbo commentedon Aug 27, 2026
Connor Peet (@connor4312), when you have a chance, could you please take a look at this issue? Thanks!
vijayupadya commentedon Sep 28, 2026
Verification failed on Windows
The fix is present in the installed Insiders build, but the idle-timeout shutdown still leaves the original
server-main.jsprocess running.Environment
226311.140.0-insiderfee7930e951e766078247fc91b2513744f8b7ef5code-tunnel-insiders.exewithout modifying the binary or timeout.2fdcab8cefa2da37172f962e2c74dcf1ed5ba0cfis included.Steps
Start the installed CLI with isolated data directories:
Request the printed URL, including its connection token, using
Invoke-WebRequest -DisableKeepAlive. Retry while the server downloads, until HTTP 200 is returned.Record the server process tree and make no further requests.
Wait for the actual one-hour idle timeout.
Check whether the original server processes exit.
Expected
The command wrapper and its Node server process both terminate after the idle timeout.
Actual
Before timeout:
After timeout:
cmd.exePID8112exited.34180, remained alive approximately 20 seconds after the timeout was observed.Relevant logs, with UTC timestamps:
Reconnection was not attempted because the original server had already failed to terminate. Test processes were explicitly cleaned up afterward.
Possible Windows-specific cause
The Windows
kill_tree()implementation invokes:without
/F, and the idle-timeout caller discards its result. After five seconds, the fallback callschild.kill(), which force-terminates only the direct child (cmd.exe), potentially leaving the Node descendant alive.The observed wrapper exit and surviving Node process are consistent with this fallback. The underlying
taskkillerror was not captured, so this remains a hypothesis for investigation.Windows verification fails. This test does not establish whether the original Linux case is fixed.
nos1609 commentedon Sep 29, 2026
Linux data point suggesting that 2fdcab8 (
kill_treeon the idle timeout) is not sufficient on its own — the ordering, not the recursion, is what leaks.Environment:
code serve-webrunning undersystemd --user, CLIcode 1.139.1(commit04c0d99…), released after the fix and containing it —stringson the binary yields theServer did not exit within … escalating to SIGKILLpath. So this is not a stale-build report.The survivor appears in one specific ordering: the
shshim thatnew_script_command()launches exits before the idle timer fires (browser tab killed, network dropped, machine suspended). serve-web then no longer has a child to walk: by the time the timer logsidle timeout reached, ending, thenode out/server-main.jsprocess has already been reparented to the user manager (PPID=systemd --user, which is PID 1 in the container variant of the original report). Its extension host is disposed, while the pty host keeps every terminal of that window alive.Measured on this machine:
ss -xshowed 0 established connections for the older of them, versus 92 for the live one;idle timeout reached, endingevents, so the timer does fire — it just cannot reach the orphan;D, all infolio_wait_bit_common, roughly 20 GiB of swap in use. After the two trees were removed the same workload sat at load ~6 with 2–4 tasks inDand ~14 GiB of swap.Would it work to record the spawned child (or kill by the process group of the shim's tree captured at spawn time) and have the idle path signal that recorded pgid, instead of walking children of a shim that may already be gone?
kill_treeon a pid whose parent exited first has nothing to recurse into — the escalation to SIGKILL then kills the already-dead shim, not the node process.Local workaround while this stays open: a
systemd --usertimer that reaps aserve-webserver only when (a) its parent is the user manager, (b) no--type=extensionHostexists anywhere in its subtree, and (c) it has been continuously observed in that state for at leastSERVER_IDLE_TIMEOUT_SECS, killing the whole tree rather than the server so the pty host does not survive it. Happy to retire it once upstream covers the ordering above.