mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-02 21:50:52 +00:00
fix: handle SIGTERM/SIGINT in ACP mode for graceful shutdown (#1884)
The ACP process was ignoring SIGTERM because signal handlers registered elsewhere in the CLI startup path (e.g., stdin raw mode restoration) override Node.js's default exit behavior. This caused the process to remain alive after the IDE sends SIGTERM, leading to zombie connections and exit code 143 errors in JetBrains IntelliJ IDEA. Add explicit SIGTERM/SIGINT handlers in runAcpAgent() that destroy stdin, which closes the ndjson stream and resolves connection.closed, allowing the process to exit gracefully. Made-with: Cursor
This commit is contained in:
parent
692e063cd7
commit
2e6ab6562b
1 changed files with 18 additions and 0 deletions
|
|
@ -87,7 +87,25 @@ export async function runAcpAgent(
|
|||
stream,
|
||||
);
|
||||
|
||||
// Handle SIGTERM/SIGINT for graceful shutdown.
|
||||
// Without this, signal handlers registered elsewhere in the CLI
|
||||
// (e.g., stdin raw mode restoration) override the default exit behavior,
|
||||
// causing the ACP process to ignore termination signals.
|
||||
const shutdownHandler = () => {
|
||||
debugLogger.debug('[ACP] Shutdown signal received, closing streams');
|
||||
try {
|
||||
process.stdin.destroy();
|
||||
} catch {
|
||||
// stdin may already be closed
|
||||
}
|
||||
};
|
||||
process.on('SIGTERM', shutdownHandler);
|
||||
process.on('SIGINT', shutdownHandler);
|
||||
|
||||
await connection.closed;
|
||||
|
||||
process.off('SIGTERM', shutdownHandler);
|
||||
process.off('SIGINT', shutdownHandler);
|
||||
}
|
||||
|
||||
function toStdioServer(server: McpServer): McpServerStdio | undefined {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue