Skip to content

Commit 3e9763d

Browse files
committed
fix(server): keep instance timeout alive
Replace AbortSignal.timeout with a managed AbortController timer so a stuck loopback request keeps the Node event loop alive until it is aborted. Preserve caller-provided signals and clear the timer when fetch settles. Validated with the instance-client timeout test and server typecheck; the full server suite passes except for the known local branch-name fixture.
1 parent a0bb7ec commit 3e9763d

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

packages/server/src/workspaces/instance-client.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ export function createInstanceClient(
5353
return createOpencodeClient({
5454
baseUrl: `http://${LOOPBACK_HOST}:${port}/`,
5555
headers,
56-
fetch: (url, init) =>
57-
fetch(url, {
58-
...(init as RequestInit),
59-
signal: (init as RequestInit)?.signal ?? AbortSignal.timeout(timeoutMs),
60-
}),
56+
fetch: (url, init) => {
57+
const requestInit = init as RequestInit
58+
if (requestInit?.signal) return fetch(url, requestInit)
59+
60+
const controller = new AbortController()
61+
const timeout = setTimeout(() => controller.abort(new DOMException("Request timed out", "TimeoutError")), timeoutMs)
62+
return fetch(url, { ...requestInit, signal: controller.signal }).finally(() => clearTimeout(timeout))
63+
},
6164
...(directory ? { directory } : {}),
6265
})
6366
}

0 commit comments

Comments
 (0)