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

Method onWorkerGone

src/mcp/query-pool.ts:241–260  ·  view source on GitHub ↗
(w: PoolWorker)

Source from the content-addressed store, hash-verified

239 // retry its in-flight job once; a job that keeps crashing workers fails
240 // gracefully so it can't loop the pool forever.
241 private onWorkerGone(w: PoolWorker): void {
242 if (!this.workers.has(w)) return; // already handled (error+exit both fire)
243 this.workers.delete(w);
244 this.pendingWorkers.delete(w);
245 this.idle = this.idle.filter((x) => x !== w);
246 this.totalCrashes++;
247 const job = this.inflight.get(w);
248 this.inflight.delete(w);
249 try { void w.terminate(); } catch { /* already gone */ }
250 if (this.healthy) this.spawnOne(); // keep capacity
251 if (job) {
252 if (job.retries < this.maxRetries && this.healthy) {
253 job.retries++;
254 this.queue.unshift(job); // head of line — retry promptly
255 } else {
256 this.settle(job, { isError: true, content: [{ type: 'text', text: 'codegraph worker crashed; please retry the call.' }] });
257 }
258 }
259 this.drain();
260 }
261
262 private drain(): void {
263 // Grow toward maxSize while queued work outstrips workers that are idle OR

Callers 1

spawnOneMethod · 0.95

Calls 6

spawnOneMethod · 0.95
settleMethod · 0.95
drainMethod · 0.95
hasMethod · 0.80
getMethod · 0.65
terminateMethod · 0.65

Tested by

no test coverage detected