MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / stop

Method stop

src/mcp/engine.ts:320–355  ·  view source on GitHub ↗

* Close everything. Used on graceful daemon shutdown (SIGTERM/idle timeout) * and on direct-mode stop. Idempotent.

()

Source from the content-addressed store, hash-verified

318 * and on direct-mode stop. Idempotent.
319 */
320 stop(): Promise<void> {
321 if (this.stopPromise) return this.stopPromise;
322 this.closed = true;
323 if (!this.cg && !this.initPromise && this.explicitProjects.size === 0 && this.writerLockRoot) {
324 releaseWriterLock(this.writerLockRoot);
325 this.writerLockRoot = null;
326 }
327
328 // Detach + terminate the worker pool first so no tool call routes to a
329 // worker mid-teardown; outstanding pool calls resolve with graceful guidance.
330 // Stopping waits for the workers to end — the pool's, and any
331 // `codegraph_status` change count still measuring: the daemon exits right
332 // after, and exiting while a worker is still starting up can crash the
333 // process.
334 this.toolHandler.setQueryPool(null);
335 const poolDown = this.queryPool ? this.queryPool.destroy() : Promise.resolve();
336 this.queryPool = null;
337 const measurementsDown = endFreshnessMeasurements();
338 const drained = this.toolHandler.closeAll();
339 this.stopPromise = Promise.all([drained, poolDown, measurementsDown]).then(async () => {
340 if (this.initPromise) await this.initPromise;
341 if (this.defaultLease) {
342 await this.defaultLease.release();
343 this.defaultLease = null;
344 this.writerLockRoot = null;
345 } else if (this.cg) {
346 this.cg.unwatch();
347 while (this.cg.isIndexing()) await new Promise((resolve) => setTimeout(resolve, 25));
348 this.cg.close();
349 }
350 this.cg = null;
351 if (this.writerLockRoot) releaseWriterLock(this.writerLockRoot);
352 this.writerLockRoot = null;
353 });
354 return this.stopPromise;
355 }
356
357 private releaseExplicitProject(cg: CodeGraph): void | Promise<void> {
358 const lease = this.explicitProjects.get(cg);

Callers

nothing calls this directly

Calls 11

releaseWriterLockFunction · 0.90
endFreshnessMeasurementsFunction · 0.90
setQueryPoolMethod · 0.80
closeAllMethod · 0.80
unwatchMethod · 0.80
isIndexingMethod · 0.80
resolveMethod · 0.65
allMethod · 0.65
releaseMethod · 0.65
closeMethod · 0.65
destroyMethod · 0.45

Tested by

no test coverage detected