Skip to content

Commit ae03472

Browse files
author
opencode-bot
committed
fix(docker): wait for server readiness; fallback to local if container not ready; prevent TUI crash/connection refused
1 parent a8dd115 commit ae03472

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

packages/opencode/src/cli/cmd/serve.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,17 @@ export const ServeCommand = cmd({
118118
const id = await new Response(p.stdout).text().then((x) => x.trim())
119119
if (code !== 0 || !id) return Server.listen({ port: args.port, hostname: args.hostname })
120120
const url = new URL("http://" + host + ":" + String(port))
121-
const until = Date.now() + 20_000
121+
const until = Date.now() + 30_000
122+
let ready = false
122123
while (Date.now() < until) {
123124
const ok = await fetch(new URL("/doc", url)).then((r) => r.ok).catch(() => false)
124-
if (ok) break
125-
await Bun.sleep(200)
125+
if (ok) {
126+
ready = true
127+
break
128+
}
129+
await Bun.sleep(250)
126130
}
131+
if (!ready) return Server.listen({ port: args.port, hostname: args.hostname })
127132
return {
128133
hostname: host,
129134
port,

packages/opencode/src/cli/cmd/tui.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,21 @@ export const TuiCommand = cmd({
216216
}
217217

218218
const url = new URL("http://" + host + ":" + String(port))
219-
const until = Date.now() + 20_000
219+
const until = Date.now() + 30_000
220+
let ready = false
220221
while (Date.now() < until) {
221222
const ok = await fetch(new URL("/doc", url)).then((r) => r.ok).catch(() => false)
222-
if (ok) break
223-
await Bun.sleep(200)
223+
if (ok) {
224+
ready = true
225+
break
226+
}
227+
await Bun.sleep(250)
228+
}
229+
if (!ready) {
230+
UI.error("docker server failed to become ready, starting locally")
231+
const stop = Bun.spawn({ cmd: [dockerBin, "stop", id], stdout: "ignore", stderr: "inherit" })
232+
await stop.exited
233+
return Server.listen({ port: args.port, hostname: args.hostname })
224234
}
225235

226236
return {

0 commit comments

Comments
 (0)