MCPcopy
hub / github.com/coder/mux / cleanup

Function cleanup

src/cli/server.ts:221–258  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

219 // Cleanup on shutdown
220 let cleanupInProgress = false;
221 const cleanup = async () => {
222 if (cleanupInProgress) return;
223 cleanupInProgress = true;
224
225 console.log("Shutting down server...");
226
227 // Force exit after timeout if cleanup hangs
228 const forceExitTimer = setTimeout(() => {
229 appendServerCrashLogSync({
230 event: "Server cleanup timed out",
231 context: { timeoutMs: 5000 },
232 });
233 console.log("Cleanup timed out, forcing exit...");
234 process.exit(1);
235 }, 5000);
236
237 try {
238 // Close all PTY sessions first
239 serviceContainer.terminalService.closeAllSessions();
240
241 // Dispose background processes
242 await serviceContainer.dispose();
243
244 // Stop server (releases lockfile, stops mDNS, closes HTTP server)
245 await serviceContainer.serverService.stopServer();
246
247 clearTimeout(forceExitTimer);
248 process.exit(0);
249 } catch (err) {
250 appendServerCrashLogSync({
251 event: "Server cleanup failed",
252 detail: err,
253 });
254 console.error("Cleanup error:", err);
255 clearTimeout(forceExitTimer);
256 process.exit(1);
257 }
258 };
259
260 process.on("SIGINT", () => void cleanup());
261 process.on("SIGTERM", () => void cleanup());

Calls 4

appendServerCrashLogSyncFunction · 0.90
stopServerMethod · 0.80
disposeMethod · 0.65
closeAllSessionsMethod · 0.45

Tested by 2

cleanupProjectSidebarDomFunction · 0.40
cleanupUseModelsHookTestFunction · 0.40