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

Method getDaemonSocket

src/mcp/index.ts:754–777  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

752 const candidates = getDaemonSocketCandidates(root);
753 const connectAnyCandidate = (deadline?: number) => connectAnyDaemonCandidate(candidates, deadline);
754 const getDaemonSocket = async () => {
755 // Fast path: a daemon may already be listening (on either candidate).
756 const probe = await connectAnyCandidate();
757 if (probe === 'version-mismatch') return null; // definitive — serve in-process, don't poll for 6s
758 if (probe && probe !== 'older-version') return probe;
759 // A daemon of an older release answered — or none did, while the project
760 // lock may still name one on a socket we don't probe (on Windows, daemons
761 // before #2278 named their pipe after the root as typed). Either way it
762 // makes way for one from this install (#2335).
763 const answered = probe === 'older-version';
764 const older = await replaceOlderDaemon(root, answered);
765 if (older === 'kept' && answered) return null;
766 // None reachable — spawn one (detached) and poll for its bind. After a
767 // replacement this launcher holds the writer slot for it meanwhile.
768 try {
769 spawnDetachedDaemon(root, older === 'stopped');
770 // Null when nothing answered in time — never bound, or a holder that
771 // never says hello: the proxy serves this session in-process.
772 return await pollForDaemon(connectAnyCandidate);
773 } finally {
774 // The new daemon has taken the slot over, or never came; a no-op unless still ours.
775 if (older === 'stopped') releaseWriterLock(root);
776 }
777 };
778 await runLocalHandshakeProxy({ getDaemonSocket, makeEngine: () => makeFallbackEngine(root), root });
779 }
780

Callers

nothing calls this directly

Calls 4

releaseWriterLockFunction · 0.90
replaceOlderDaemonFunction · 0.85
spawnDetachedDaemonFunction · 0.85
pollForDaemonFunction · 0.85

Tested by

no test coverage detected