Skip to content

Commit 5608ab7

Browse files
committed
fix(cloud): cold-start tuning for the headless serve container
First real CF cold start 503'd (companion didn't bind within the 60s poll). - wrangler.toml: instance_type standard(½ vCPU) -> standard-3 (2 vCPU/8GiB); WebKitGTK + Xvfb init needs real CPU. Also clears the standard->standard-1 rename warning. - index.ts: health poll 60s -> 120s for a heavy first-boot init. - start-serve.sh: skip if a serve host is already running (the Worker calls startProcess on every not-ready request; a 2nd serve fought for the port).
1 parent 0fdce48 commit 5608ab7

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

cloud/scripts/start-serve.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ git config --global user.name "${HELMOR_GIT_NAME:-Helmor Cloud}" || true
3232
git config --global user.email "${HELMOR_GIT_EMAIL:-cloud@helmor.app}" || true
3333
git config --global --add safe.directory '*' || true
3434

35+
# Idempotency: the Worker calls startProcess on every not-yet-ready request, so
36+
# bail out if a serve host is already running — a second one would fight for the
37+
# companion port and neither would bind cleanly.
38+
if pgrep -f "${HELMOR_HOME}/helmor serve" >/dev/null 2>&1; then
39+
echo "helmor-start-serve: serve already running; nothing to do"
40+
exit 0
41+
fi
42+
3543
# 1. Independent Xvfb daemon (idempotent — skip if one is already running).
3644
if ! pgrep -x Xvfb >/dev/null 2>&1; then
3745
Xvfb "$DISPLAY" -screen 0 1280x800x24 -nolisten tcp >/tmp/xvfb.log 2>&1 &

cloud/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ async function ensureServe(
8181
},
8282
});
8383

84-
// Cold start: Xvfb + GTK/WebKit init + companion bind. Poll up to ~60s.
85-
for (let attempt = 0; attempt < 120; attempt++) {
84+
// Cold start: Xvfb + GTK/WebKit init + companion bind. Poll up to ~120s
85+
// (WebKitGTK init is heavy on a fresh container's first boot).
86+
for (let attempt = 0; attempt < 240; attempt++) {
8687
if (await healthOk(sandbox, port)) return;
8788
await sleep(500);
8889
}

cloud/wrangler.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ compatibility_flags = ["nodejs_compat"]
2121
[[containers]]
2222
class_name = "Sandbox"
2323
image = "../Dockerfile"
24-
instance_type = "standard"
24+
instance_type = "standard-3"
2525
max_instances = 1
2626

2727
[[durable_objects.bindings]]

0 commit comments

Comments
 (0)