fix(cli): harden no-daemon teardown
This commit is contained in:
8
cli.ts
8
cli.ts
@@ -79,10 +79,10 @@ async function runInProcess(
|
|||||||
const result = await runCommand(cmdArg, client, uri, params);
|
const result = await runCommand(cmdArg, client, uri, params);
|
||||||
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
||||||
} finally {
|
} finally {
|
||||||
// Fire-And-Forget Shutdown - With `gopls -remote=auto` (and similar)
|
// Hard Teardown - The no-daemon path is short-lived/debug-only. Avoid
|
||||||
// the spawned process is a thin client to a background daemon; a
|
// graceful JSON-RPC shutdown because the server stdio stream may already
|
||||||
// graceful shutdown can hang the parent. Kick it off but don't wait.
|
// be closed, which can surface ERR_STREAM_DESTROYED during process exit.
|
||||||
void client.dispose();
|
void client.dispose({ graceful: false });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -252,15 +252,22 @@ export class LspClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Dispose - Best-effort shutdown; kills the process if it doesn't exit.
|
// Dispose - Best-effort shutdown; kills the process if it doesn't exit.
|
||||||
async dispose(): Promise<void> {
|
async dispose(options: { graceful?: boolean } = {}): Promise<void> {
|
||||||
|
const graceful = options.graceful ?? true;
|
||||||
if (this.conn) {
|
if (this.conn) {
|
||||||
try {
|
if (graceful) {
|
||||||
await this.conn.sendRequest("shutdown", undefined);
|
try {
|
||||||
this.conn.sendNotification("exit");
|
await this.conn.sendRequest("shutdown", undefined);
|
||||||
} catch {
|
this.conn.sendNotification("exit");
|
||||||
// Ignore - we're tearing down anyway.
|
} catch {
|
||||||
|
// Ignore - we're tearing down anyway.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.conn.dispose();
|
||||||
|
} catch {
|
||||||
|
// Ignore - connection may already be closed.
|
||||||
}
|
}
|
||||||
this.conn.dispose();
|
|
||||||
}
|
}
|
||||||
if (this.proc && !this.proc.killed) {
|
if (this.proc && !this.proc.killed) {
|
||||||
this.proc.kill();
|
this.proc.kill();
|
||||||
|
|||||||
Reference in New Issue
Block a user