nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] On Windows an LSP server started through a .cmd shim keeps running after the client is stopped

Open addyCooks opened this issue 1 week ago • 1 comments

Description

On Windows, npm-installed language servers start through a .cmd shim, so child.kill() only ends cmd.exe. A server that ignores the LSP exit request (or is stuck) keeps running after LSPClient.stop().

Environment

  • OS: Windows 11 Home 10.0.26300
  • Node version: v22.22.3
  • Nanocoder version: 1.32.0 (built from main at eb7dee57)
  • Provider: Not provider-specific
  • Model: Not model-specific

Steps to Reproduce

  1. Create a .cmd shim that runs a node script. The script answers initialize and shutdown, ignores exit and stdin end, stays alive, and writes its pid to a file.
  2. const client = new LSPClient({name: 'hung-server', command: '<shim>.cmd', args: ['--stdio'], languages: ['ts']}), then await client.start() and await client.stop().
  3. Wait 1.5 seconds and check whether the pid from the file is still running.

Expected Behavior

The server process is gone after stop().

Actual Behavior

The pid is still running.

Logs/Screenshots

server pid 22436 is still running after stop()

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder (main)

Suggested fix:

  • source/lsp/lsp-client.ts:179 (this.process.kill() in stop()) and :148 (child.kill() after a failed start): use signalProcessTree(child) from source/utils/process-tree.ts, which already runs taskkill /T /F on Windows.
  • Add a Windows-only test like the steps above.

Related: PR #1699 (the same fix for execute_bash).

addyCooks avatar Nov 23 '26 07:11 addyCooks

I'd like to pick this up. I'm on Windows 11, so I can reproduce it with a .cmd shim. Plan: use signalProcessTree in stop() and in the failed-start path of LSPClient, and add a Windows-only test that checks the server pid is gone after stop().

hanming5 avatar Nov 23 '26 11:11 hanming5