* Forcefully stops the CLI server without graceful cleanup. * * Use this when stop fails or takes too long. This method: * - Clears all sessions immediately without destroying them * - Force closes the connection * - Sends SIGKILL to the CLI process (if spawned by th
()
| 1049 | * ``` |
| 1050 | */ |
| 1051 | async forceStop(): Promise<void> { |
| 1052 | this.forceStopping = true; |
| 1053 | |
| 1054 | // Clear sessions immediately without trying to destroy them |
| 1055 | for (const session of this.sessions.values()) { |
| 1056 | session._markDisconnected(); |
| 1057 | } |
| 1058 | this.sessions.clear(); |
| 1059 | |
| 1060 | // Force close connection. Suppress writer failures first so teardown |
| 1061 | // write rejections don't surface as unhandled rejections. |
| 1062 | if (this.messageWriter) { |
| 1063 | this.messageWriter.suppressWriteErrors = true; |
| 1064 | } |
| 1065 | if (this.connection) { |
| 1066 | try { |
| 1067 | this.connection.dispose(); |
| 1068 | } catch { |
| 1069 | // Ignore errors during force stop |
| 1070 | } |
| 1071 | this.connection = null; |
| 1072 | this.messageWriter = null; |
| 1073 | this._rpc = null; |
| 1074 | this._internalRpc = null; |
| 1075 | } |
| 1076 | |
| 1077 | // Clear models cache |
| 1078 | this.modelsCache = null; |
| 1079 | |
| 1080 | if (this.socket) { |
| 1081 | try { |
| 1082 | this.socket.destroy(); // destroy() is more forceful than end() |
| 1083 | } catch { |
| 1084 | // Ignore errors |
| 1085 | } |
| 1086 | this.socket = null; |
| 1087 | } |
| 1088 | |
| 1089 | // Force kill CLI process (only if we spawned it) |
| 1090 | if (this.cliProcess && !this.isExternalServer) { |
| 1091 | try { |
| 1092 | this.cliProcess.kill("SIGKILL"); |
| 1093 | } catch { |
| 1094 | // Ignore errors |
| 1095 | } |
| 1096 | this.cliProcess = null; |
| 1097 | } |
| 1098 | |
| 1099 | if (this.cliStartTimeout) { |
| 1100 | clearTimeout(this.cliStartTimeout); |
| 1101 | this.cliStartTimeout = null; |
| 1102 | } |
| 1103 | |
| 1104 | this.state = "disconnected"; |
| 1105 | this.runtimePort = null; |
| 1106 | this.stderrBuffer = ""; |
| 1107 | this.processExitPromise = null; |
| 1108 | } |