MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / waitForPort

Function waitForPort

src/cm/lsp/serverLauncher.ts:221–252  ·  view source on GitHub ↗

* Wait for the port file to be available after server signals ready. * This is the most efficient approach: wait for ready signal, then read port.

(
  serverId: string,
  serverName: string,
  session: string,
  timeout = 10000,
)

Source from the content-addressed store, hash-verified

219 * This is the most efficient approach: wait for ready signal, then read port.
220 */
221async function waitForPort(
222 serverId: string,
223 serverName: string,
224 session: string,
225 timeout = 10000,
226): Promise<PortInfo | null> {
227 // First, wait for the server to signal it's ready
228 const ready = await waitForServerReady(serverId, timeout);
229
230 if (!ready) {
231 console.warn(
232 `[LSP:${serverId}] Server did not signal ready within timeout`,
233 );
234 }
235
236 // The port file should be available now (axs writes it before printing "listening on")
237 // Read it directly
238 const portInfo = await getLspPort(serverName, session);
239
240 if (!portInfo && ready) {
241 // Server signaled ready but port file not found - retry a few times
242 for (let i = 0; i < 5; i++) {
243 await sleep(100);
244 const retryPortInfo = await getLspPort(serverName, session);
245 if (retryPortInfo) {
246 return retryPortInfo;
247 }
248 }
249 }
250
251 return portInfo;
252}
253
254/**
255 * Check if we can reuse an existing server by testing the port.

Callers 1

ensureServerRunningFunction · 0.85

Calls 3

waitForServerReadyFunction · 0.85
getLspPortFunction · 0.85
sleepFunction · 0.85

Tested by

no test coverage detected