Skip to content

VSCode server LEAKs server-main.js process. #332764

Description

@Kidsunbo

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:

  1. Start code serve-web, connect once, then disconnect all clients.
  2. 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:

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());

}
_ = &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():

/// 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

  1. changed the title [-]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[/+] on Aug 26, 2026
  2. changed the title [-]C ode serve-web leaves orphaned server-main.js processes after idle timeout[/-] [+]VSCode server LEAKs server-main.js process.[/+] on Aug 26, 2026
  3. Kidsunbo commented on Aug 27, 2026

    @Kidsunbo
    ContributorAuthor

    Connor Peet (@connor4312), when you have a chance, could you please take a look at this issue? Thanks!

  4. added
    bug
    on Aug 27, 2026
  5. added
    unreleased
    on Sep 22, 2026
  6. added this to the 1.140.0 milestone on Sep 22, 2026
  7. added
    insiders-released
    and removed
    unreleased
    on Sep 23, 2026
  8. vijayupadya commented on Sep 28, 2026

    @vijayupadya
    Contributor

    Verification failed on Windows

    The fix is present in the installed Insiders build, but the idle-timeout shutdown still leaves the original server-main.js process running.

    Environment

    • OS: Windows 11 Enterprise x64, build 22631
    • VS Code: 1.140.0-insider
    • Commit: fee7930e951e766078247fc91b2513744f8b7ef5
    • Tested the installed code-tunnel-insiders.exe without modifying the binary or timeout.
    • Confirmed fix commit 2fdcab8cefa2da37172f962e2c74dcf1ed5ba0cf is included.

    Steps

    1. Start the installed CLI with isolated data directories:

      & "$env:LOCALAPPDATA\Programs\Microsoft VS Code Insiders\bin\code-tunnel-insiders.exe" `
        --cli-data-dir "$env:TEMP\vscode-332764-cli" `
        --log debug `
        serve-web `
        --host 127.0.0.1 `
        --port 0 `
        --commit-id fee7930e951e766078247fc91b2513744f8b7ef5 `
        --server-data-dir "$env:TEMP\vscode-332764-server" `
        --disable-telemetry `
        --accept-server-license-terms
    2. Request the printed URL, including its connection token, using Invoke-WebRequest -DisableKeepAlive. Retry while the server downloads, until HTTP 200 is returned.

    3. Record the server process tree and make no further requests.

    4. Wait for the actual one-hour idle timeout.

    5. Check whether the original server processes exit.

    This test used an HTTP client rather than a full browser session. It exercised the CLI connection counter and real idle-timeout shutdown path; no time acceleration was used.

    Expected

    The command wrapper and its Node server process both terminate after the idle timeout.

    Actual

    Before timeout:

    code-tunnel-insiders.exe  PID 25516
    └─ cmd.exe               PID 8112
       └─ node.exe           PID 34180  (out/server-main.js)
    

    After timeout:

    • cmd.exe PID 8112 exited.
    • The original Node server, PID 34180, remained alive approximately 20 seconds after the timeout was observed.
    • Process creation time was checked to exclude PID reuse.

    Relevant logs, with UTC timestamps:

    [2026-09-28 19:20:37] info [fee7930 process]: idle timeout reached, ending
    [2026-09-28 19:20:43] warn [fee7930 process]: server did not exit within 5s after kill_tree; escalating to force kill
    

    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:

    taskkill /t /pid <pid>
    

    without /F, and the idle-timeout caller discards its result. After five seconds, the fallback calls child.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 taskkill error 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.

  9. removed
    insiders-released
    on Sep 28, 2026
  10. nos1609 commented on Sep 29, 2026

    @nos1609

    Linux data point suggesting that 2fdcab8 (kill_tree on the idle timeout) is not sufficient on its own — the ordering, not the recursion, is what leaks.

    Environment: code serve-web running under systemd --user, CLI code 1.139.1 (commit 04c0d99…), released after the fix and containing it — strings on the binary yields the Server did not exit within … escalating to SIGKILL path. So this is not a stale-build report.

    The survivor appears in one specific ordering: the sh shim that new_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 logs idle timeout reached, ending, the node out/server-main.js process 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:

    • two such servers lived 30 h and 34 h next to the current one; ss -x showed 0 established connections for the older of them, versus 92 for the live one;
    • the journal records five idle timeout reached, ending events, so the timer does fire — it just cannot reach the orphan;
    • while both were alive: load average 47–57 on 8 cores with 26 tasks in D, all in folio_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 in D and ~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_tree on 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 --user timer that reaps a serve-web server only when (a) its parent is the user manager, (b) no --type=extensionHost exists anywhere in its subtree, and (c) it has been continuously observed in that state for at least SERVER_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions