From 0ac92ec4d56e51e0be1cf4b3f863a11355ff7443 Mon Sep 17 00:00:00 2001 From: Madraka <8898640+Madraka@users.noreply.github.com> Date: Sat, 28 Nov 2026 23:31:26 +0300 Subject: [PATCH 1/3] ci(docker): bound every Swarm smoke step and print the state when one fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #306: `Build edge` has been cancelled at 90 min on every run since 2026-11-23, inside `scripts/swarm-smoke.sh`. The cancelled job's log shows the step printed nothing (not even its first "✓") and ends with "Terminate orphan process: (curl)": the first wait loop's `curl -sf "$studio/api/health"` had no time limit and never returned, so Helm, Trivy, arm64 and the edge tag never ran. - Every curl is `--connect-timeout 5 --max-time 15`; every docker call runs under `timeout` (120 s; 30–60 s in cleanup); `docker stack deploy` shows its output and fails the run. - The wait loop prints progress every 30 s (replicas, health code) and fails with them. - `fail` prints services, the tasks and logs of both services (cloudhal and seaweedfs), the stack's containers, and a verbose bounded curl of /api/health over 127.0.0.1 and localhost. - docker.yml: `timeout-minutes` 15 on the Swarm step, 20 on Helm, 15 on Trivy. The root cause comes from this run's log; the fix follows in this PR. Refs #306 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com> --- .github/workflows/docker.yml | 5 +++ scripts/swarm-smoke.sh | 67 +++++++++++++++++++++++------------- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 355d5556..0f40eae4 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -221,13 +221,18 @@ jobs: docker tag "$SMOKE_IMAGE" cloudhal:ci env: SMOKE_IMAGE: ${{ steps.ref.outputs.image }} + # Every step after the build is bounded (#306): a hang fails with the script's diagnostics + # instead of running into the job's 90-minute timeout and skipping everything after it. - name: Swarm smoke test + timeout-minutes: 15 run: scripts/swarm-smoke.sh cloudhal:ci - name: Helm smoke test (kind) + timeout-minutes: 20 run: | kind version && helm version --short scripts/helm-smoke.sh cloudhal:ci - name: Trivy scan + timeout-minutes: 15 uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 with: image-ref: ${{ steps.ref.outputs.image }} diff --git a/scripts/swarm-smoke.sh b/scripts/swarm-smoke.sh index 0809d83e..44b3fcd0 100755 --- a/scripts/swarm-smoke.sh +++ b/scripts/swarm-smoke.sh @@ -12,71 +12,92 @@ root=$(cd "$(dirname "$0")/.." && pwd) stack="chsmoke$$" work=$(mktemp -d) started_swarm=no +# Every network call and docker command is bounded (#306): a port that accepts a connection and +# never answers, or a docker command that waits on the engine, fails the run with the state below +# instead of hanging until the job's timeout cancels it with nothing printed. +http() { curl --connect-timeout 5 --max-time 15 "$@"; } +d() { timeout 120 docker "$@"; } step() { echo "✓ $*"; } fail() { echo "✗ $*" >&2 - docker service ps "${stack}_cloudhal" --no-trunc >&2 || true - docker service logs --tail 80 "${stack}_cloudhal" >&2 || true + { + echo "--- services" + timeout 30 docker service ls || true + for svc in cloudhal seaweedfs; do + echo "--- tasks: ${stack}_$svc" + timeout 30 docker service ps "${stack}_$svc" --no-trunc || true + echo "--- logs: ${stack}_$svc" + timeout 30 docker service logs --tail 80 --timestamps "${stack}_$svc" || true + done + echo "--- containers" + timeout 30 docker ps -a --filter "label=com.docker.stack.namespace=$stack" || true + echo "--- health, verbose (IPv4 and localhost)" + curl -v --connect-timeout 5 --max-time 10 "http://127.0.0.1:$port/api/health" 2>&1 | tail -20 || true + curl -v --connect-timeout 5 --max-time 10 "http://localhost:$port/api/health" 2>&1 | tail -20 || true + } >&2 exit 1 } cleanup() { - docker stack rm "$stack" >/dev/null 2>&1 || true + timeout 60 docker stack rm "$stack" || true for i in $(seq 1 30); do - [ -z "$(docker ps -q --filter "label=com.docker.stack.namespace=$stack")" ] && break + [ -z "$(timeout 20 docker ps -q --filter "label=com.docker.stack.namespace=$stack")" ] && break sleep 2 done - docker secret ls --format '{{.Name}}' | grep '^cloudhal_' | xargs -r docker secret rm >/dev/null 2>&1 || true - docker volume rm cloudhal-data-1 cloudhal-data-2 cloudhal-data-3 "${stack}_cloudhal-store" >/dev/null 2>&1 || true - [ "$started_swarm" = yes ] && docker swarm leave --force >/dev/null 2>&1 || true + timeout 30 docker secret ls --format '{{.Name}}' | grep '^cloudhal_' | xargs -r timeout 30 docker secret rm >/dev/null || true + timeout 60 docker volume rm cloudhal-data-1 cloudhal-data-2 cloudhal-data-3 "${stack}_cloudhal-store" >/dev/null 2>&1 || true + if [ "$started_swarm" = yes ]; then timeout 60 docker swarm leave --force || true; fi rm -rf "$work" } trap cleanup EXIT -if [ "$(docker info --format '{{.Swarm.LocalNodeState}}')" != active ]; then - docker swarm init >/dev/null +if [ "$(d info --format '{{.Swarm.LocalNodeState}}')" != active ]; then + d swarm init >/dev/null started_swarm=yes fi -if docker secret ls --format '{{.Name}}' | grep -q '^cloudhal_'; then +if d secret ls --format '{{.Name}}' | grep -q '^cloudhal_'; then echo "this swarm already has cloudhal_* secrets: run the smoke test on a scratch engine" >&2 started_swarm=no exit 1 fi -docker node update --label-add cloudhal.store=true "$(docker node ls --format '{{.Self}} {{.ID}}' | awk '$1=="true"{print $2}')" >/dev/null -docker run --rm "$image" secrets > "$work/secrets.env" -"$root/deploy/swarm/create-secrets.sh" < "$work/secrets.env" >/dev/null +d node update --label-add cloudhal.store=true "$(d node ls --format '{{.Self}} {{.ID}}' | awk '$1=="true"{print $2}')" >/dev/null +d run --rm "$image" secrets > "$work/secrets.env" +timeout 120 "$root/deploy/swarm/create-secrets.sh" < "$work/secrets.env" >/dev/null set -a # shellcheck disable=SC1091 . "$work/secrets.env" set +a local_tag="ghcr.io/cloudhal-dev/cloudhal:smoke-$$" -docker tag "$image" "$local_tag" +d tag "$image" "$local_tag" CLOUDHAL_TAG="smoke-$$" CLOUDHAL_PORT=$port CLOUDHAL_SITE_PORT=$((port + 1)) CLOUDHAL_SITE_NAME="Smoke Site" \ - docker stack deploy -c "$root/deploy/swarm/stack.yml" "$stack" >/dev/null 2>&1 + timeout 120 docker stack deploy -c "$root/deploy/swarm/stack.yml" "$stack" || fail "docker stack deploy" studio="http://localhost:$port" site="http://127.0.0.1:$((port + 1))" for i in $(seq 1 90); do - [ "$(docker service ls --filter "name=${stack}_cloudhal" --format '{{.Replicas}}')" = "2/2" ] && - curl -sf -o /dev/null "$studio/api/health" && break - [ "$i" = 90 ] && fail "the stack did not come up within 270 s" + replicas=$(d service ls --filter "name=${stack}_cloudhal" --format '{{.Replicas}}') + health=$(http -s -o /dev/null -w '%{http_code}' "$studio/api/health" || true) + [ "$replicas" = "2/2" ] && [ "$health" = 200 ] && break + # Progress, so a slow start shows where it is. + [ $((i % 10)) = 0 ] && echo "… ${i}: replicas $replicas, health ${health:-none}" + [ "$i" = 90 ] && fail "the stack did not come up within the wait (replicas $replicas, health ${health:-none})" sleep 3 done step "two instances and the store are up" for i in $(seq 1 60); do - [ "$(curl -s -o /dev/null -w '%{http_code}' "$site/")" = 503 ] && break + [ "$(http -s -o /dev/null -w '%{http_code}' "$site/" || true)" = 503 ] && break [ "$i" = 60 ] && fail "the site never answered its 503 before the first publish" sleep 2 done pw=$(openssl rand -hex 12) -code=$(curl -s -c "$work/jar" -o /dev/null -w '%{http_code}' "$studio/api/auth/sign-up/email" -H "origin: $studio" \ +code=$(http -s -c "$work/jar" -o /dev/null -w '%{http_code}' "$studio/api/auth/sign-up/email" -H "origin: $studio" \ -H 'content-type: application/json' -H "x-cloudhal-setup-token: $CLOUDHAL_SETUP_TOKEN" \ -d "{\"name\":\"Smoke Owner\",\"email\":\"owner@example.com\",\"password\":\"$pw\"}") [ "$code" = 200 ] || fail "sign-up of the first owner ($code)" -code=$(curl -s -b "$work/jar" -o /dev/null -w '%{http_code}' -X POST "$studio/api/sites/$CLOUDHAL_SITE_ID/snapshots" \ +code=$(http -s -b "$work/jar" -o /dev/null -w '%{http_code}' -X POST "$studio/api/sites/$CLOUDHAL_SITE_ID/snapshots" \ -H "origin: $studio" -H 'content-type: application/json' -d '{"publish":true}') [ "$code" = 201 ] || fail "publish ($code)" -for i in 1 2 3 4; do curl -s "$site/" | grep -q "Smoke Site" || fail "the site after the publish"; done +for i in 1 2 3 4; do http -s "$site/" | grep -q "Smoke Site" || fail "the site after the publish"; done step "the owner signed up; a publish is live on the next request through the routing mesh" -docker rmi "$local_tag" >/dev/null 2>&1 || true +timeout 60 docker rmi "$local_tag" >/dev/null 2>&1 || true echo echo "Swarm smoke test passed." From 0afd1f98fa273de5646ea1105efa0b22b2dfde75 Mon Sep 17 00:00:00 2001 From: Madraka <8898640+Madraka@users.noreply.github.com> Date: Sat, 28 Nov 2026 23:53:16 +0300 Subject: [PATCH 2/3] ci(docker): Swarm smoke waits on wall-clock deadlines and probes the app from inside Run 46186851063 (#308) narrowed #306: the stack reports replicas 2/2 from the first minute, but /api/health on the published port never answers (curl 000 after 15 s) for the whole wait. The wait loop's 90 tries of up to 18 s each outran the step's 15-minute timeout, so `fail` never printed its state. - The waits are wall-clock deadlines (240 s for the stack, 120 s for the site's 503) with short probes (connect 3 s, max 5 s), so `fail` always runs well inside the step's 20 minutes. - Progress lines show the published port over localhost and 127.0.0.1 and /api/health from inside a cloudhal container (node fetch, bypassing the routing mesh): a stuck app and a port that is not forwarded look different. - `fail` adds health inside each container, host listeners on the published ports, the ingress network, the docker/kernel/firewall versions and the NAT rules for the ports. Refs #306 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com> --- .github/workflows/docker.yml | 2 +- scripts/swarm-smoke.sh | 43 +++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0f40eae4..2f4532be 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -224,7 +224,7 @@ jobs: # Every step after the build is bounded (#306): a hang fails with the script's diagnostics # instead of running into the job's 90-minute timeout and skipping everything after it. - name: Swarm smoke test - timeout-minutes: 15 + timeout-minutes: 20 run: scripts/swarm-smoke.sh cloudhal:ci - name: Helm smoke test (kind) timeout-minutes: 20 diff --git a/scripts/swarm-smoke.sh b/scripts/swarm-smoke.sh index 44b3fcd0..28b41e10 100755 --- a/scripts/swarm-smoke.sh +++ b/scripts/swarm-smoke.sh @@ -18,6 +18,14 @@ started_swarm=no http() { curl --connect-timeout 5 --max-time 15 "$@"; } d() { timeout 120 docker "$@"; } step() { echo "✓ $*"; } +# /api/health from inside one cloudhal container (bypassing the published port and the routing +# mesh): tells a stuck app from a port that is not forwarded. +inside() { + local ctr + ctr=$(timeout 20 docker ps -q --filter "label=com.docker.swarm.service.name=${stack}_cloudhal" | head -1) + [ -n "$ctr" ] || { echo "no container"; return; } + timeout 20 docker exec "$ctr" node -e "fetch('http://127.0.0.1:8787/api/health',{signal:AbortSignal.timeout(8000)}).then(r=>console.log(r.status),e=>console.log('error',e.cause?.code??e.name))" 2>&1 | tail -1 +} fail() { echo "✗ $*" >&2 { @@ -31,6 +39,17 @@ fail() { done echo "--- containers" timeout 30 docker ps -a --filter "label=com.docker.stack.namespace=$stack" || true + echo "--- health inside each cloudhal container" + for ctr in $(timeout 20 docker ps -q --filter "label=com.docker.swarm.service.name=${stack}_cloudhal"); do + echo "$ctr: $(timeout 20 docker exec "$ctr" node -e "fetch('http://127.0.0.1:8787/api/health',{signal:AbortSignal.timeout(8000)}).then(r=>console.log(r.status),e=>console.log('error',e.cause?.code??e.name))" 2>&1 | tail -1)" + done + echo "--- listeners on the published ports" + (ss -ltnp 2>/dev/null || true) | grep -E ":(${port}|$((port + 1)))\b" || echo "none on the host" + echo "--- ingress network" + timeout 30 docker network inspect ingress --format '{{json .IPAM.Config}} peers={{len .Peers}} containers={{len .Containers}}' || true + timeout 30 docker info --format 'docker {{.ServerVersion}}, swarm {{.Swarm.LocalNodeState}}, kernel {{.KernelVersion}}, firewall {{.FirewallBackend}}' 2>/dev/null || timeout 30 docker version --format 'docker {{.Server.Version}}' || true + echo "--- NAT rules for the published ports" + (sudo -n iptables-save -t nat 2>/dev/null || sudo -n nft list ruleset 2>/dev/null || true) | grep -E "${port}|$((port + 1))|DOCKER-INGRESS" | head -20 echo "--- health, verbose (IPv4 and localhost)" curl -v --connect-timeout 5 --max-time 10 "http://127.0.0.1:$port/api/health" 2>&1 | tail -20 || true curl -v --connect-timeout 5 --max-time 10 "http://localhost:$port/api/health" 2>&1 | tail -20 || true @@ -72,19 +91,27 @@ CLOUDHAL_TAG="smoke-$$" CLOUDHAL_PORT=$port CLOUDHAL_SITE_PORT=$((port + 1)) CLO timeout 120 docker stack deploy -c "$root/deploy/swarm/stack.yml" "$stack" || fail "docker stack deploy" studio="http://localhost:$port" site="http://127.0.0.1:$((port + 1))" -for i in $(seq 1 90); do +# Wall-clock deadlines, well inside the step's timeout-minutes, so `fail` always gets to print. +deadline=$((SECONDS + 240)) +i=0 +while :; do + i=$((i + 1)) replicas=$(d service ls --filter "name=${stack}_cloudhal" --format '{{.Replicas}}') - health=$(http -s -o /dev/null -w '%{http_code}' "$studio/api/health" || true) + health=$(curl --connect-timeout 3 --max-time 5 -s -o /dev/null -w '%{http_code}' "$studio/api/health" || true) [ "$replicas" = "2/2" ] && [ "$health" = 200 ] && break - # Progress, so a slow start shows where it is. - [ $((i % 10)) = 0 ] && echo "… ${i}: replicas $replicas, health ${health:-none}" - [ "$i" = 90 ] && fail "the stack did not come up within the wait (replicas $replicas, health ${health:-none})" + # Progress, so a slow start shows where it is: the published port over localhost and 127.0.0.1, + # and the app inside its container. + if [ $((i % 6)) = 0 ]; then + v4=$(curl --connect-timeout 3 --max-time 5 -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:$port/api/health" || true) + echo "… ${SECONDS}s: replicas $replicas, health localhost ${health:-none} / 127.0.0.1 ${v4:-none} / inside $(inside)" + fi + [ "$SECONDS" -ge "$deadline" ] && fail "the stack did not come up within 240 s (replicas $replicas, health ${health:-none})" sleep 3 done step "two instances and the store are up" -for i in $(seq 1 60); do - [ "$(http -s -o /dev/null -w '%{http_code}' "$site/" || true)" = 503 ] && break - [ "$i" = 60 ] && fail "the site never answered its 503 before the first publish" +deadline=$((SECONDS + 120)) +until [ "$(curl --connect-timeout 3 --max-time 5 -s -o /dev/null -w '%{http_code}' "$site/" || true)" = 503 ]; do + [ "$SECONDS" -ge "$deadline" ] && fail "the site never answered its 503 before the first publish" sleep 2 done pw=$(openssl rand -hex 12) From 5557faec2ce65ad6b9c3a6965727cd5a8708c39a Mon Sep 17 00:00:00 2001 From: Madraka <8898640+Madraka@users.noreply.github.com> Date: Sun, 29 Nov 2026 00:03:44 +0300 Subject: [PATCH 3/3] fix(ci): the Swarm smoke test reaches Studio over 127.0.0.1, not localhost (#306) Root cause, from run 46188727714's probes: the app answers /api/health inside its container (200) and on the published port over 127.0.0.1 (200), but over `localhost` never (000). curl's verbose output shows `localhost` resolving to ::1 first and "Established connection to localhost (::1 port 58787)", then no reply: the routing mesh publishes IPv4 only, a connection to [::1]: is accepted on GitHub's runners and never answered, and since it connected, curl never falls back to IPv4. The script's Studio URL was `http://localhost:$port` (its site URL was already 127.0.0.1), so the first wait hung, unbounded until #308, from the runner image change on 2026-11-23. - scripts/swarm-smoke.sh: Studio at http://127.0.0.1:$port, with the reason; the progress line shows the published port and the in-container probe; the bounds and diagnostics stay. - docs/guides/self-host.md and deploy/swarm/README.md: on the node itself use 127.0.0.1, not localhost, with the same reason. Seen in the same log, not changed here: two instances starting together race on a migration ("0004_audit_actor_name failed: duplicate column name: actor_name"); reported separately. Closes #306 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com> --- deploy/swarm/README.md | 1 + docs/guides/self-host.md | 2 ++ scripts/swarm-smoke.sh | 14 +++++++------- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/deploy/swarm/README.md b/deploy/swarm/README.md index 28bda047..763e726b 100644 --- a/deploy/swarm/README.md +++ b/deploy/swarm/README.md @@ -32,6 +32,7 @@ **Notes:** +- **On the node itself, use `127.0.0.1`, not `localhost`.** The routing mesh publishes IPv4 only. Where `localhost` resolves to `::1` first, a connection to the published port is accepted and never answered (#306). - **Peer traffic** (port 7000) travels on the stack's own overlay, `10.231.0.0/24`, which is `encrypted`. Each task advertises its address there (`CLOUDHAL_CLUSTER_ADVERTISE=auto:10.231.0.0/24`). If that subnet is taken in your swarm, change it in both places. - **Working copies:** each task's `/data` is a volume named `cloudhal-data-` on the node it runs on. It holds only working copies; the store holds the installation, so back up the `cloudhal-store` volume (guide, "Backup and restore"). - **TLS:** put a TLS proxy or load balancer in front of ports 8787 and 8788. It must append the client's address to `X-Forwarded-For`. Then set `CLOUDHAL_BASE_URL` and `CLOUDHAL_BEHIND_PROXY=1` when you deploy. The routing mesh hides the client's address, so without a proxy rate limits share one bucket per path. diff --git a/docs/guides/self-host.md b/docs/guides/self-host.md index 046a4f9c..ab336d90 100644 --- a/docs/guides/self-host.md +++ b/docs/guides/self-host.md @@ -151,6 +151,8 @@ The cluster runs on workerd's experimental cluster mode, so treat several instan - two or more replicas behind the routing mesh, each advertising its address on the stack's encrypted overlay (`CLOUDHAL_CLUSTER_ADVERTISE=auto:`); - a volume per task slot, and `start-first` rolling updates; - SeaweedFS pinned to a labelled node. + + The routing mesh publishes IPv4 only. On the node itself, open `http://127.0.0.1:8787`, not `http://localhost:8787`: on hosts where `localhost` resolves to `::1` first, the connection is accepted and never answered. - **Kubernetes:** the Helm chart in [`deploy/helm/cloudhal`](https://github.com/cloudhal-dev/cloudhal/tree/main/deploy/helm/cloudhal) is published with each release as `oci://ghcr.io/cloudhal-dev/charts/cloudhal`. It has these parts: - a StatefulSet whose pods advertise `.-peers` through a headless Service; - readiness on `/ready`, and a NetworkPolicy that admits the cluster port from the release's own pods only; diff --git a/scripts/swarm-smoke.sh b/scripts/swarm-smoke.sh index 28b41e10..bffdb58d 100755 --- a/scripts/swarm-smoke.sh +++ b/scripts/swarm-smoke.sh @@ -89,7 +89,10 @@ local_tag="ghcr.io/cloudhal-dev/cloudhal:smoke-$$" d tag "$image" "$local_tag" CLOUDHAL_TAG="smoke-$$" CLOUDHAL_PORT=$port CLOUDHAL_SITE_PORT=$((port + 1)) CLOUDHAL_SITE_NAME="Smoke Site" \ timeout 120 docker stack deploy -c "$root/deploy/swarm/stack.yml" "$stack" || fail "docker stack deploy" -studio="http://localhost:$port" +# 127.0.0.1, never localhost (#306): the routing mesh publishes IPv4 only, but on GitHub's runners +# `localhost` resolves to ::1 first and a connection to [::1]: is accepted and then never +# answered, so curl neither gets a reply nor falls back to IPv4. +studio="http://127.0.0.1:$port" site="http://127.0.0.1:$((port + 1))" # Wall-clock deadlines, well inside the step's timeout-minutes, so `fail` always gets to print. deadline=$((SECONDS + 240)) @@ -99,12 +102,9 @@ while :; do replicas=$(d service ls --filter "name=${stack}_cloudhal" --format '{{.Replicas}}') health=$(curl --connect-timeout 3 --max-time 5 -s -o /dev/null -w '%{http_code}' "$studio/api/health" || true) [ "$replicas" = "2/2" ] && [ "$health" = 200 ] && break - # Progress, so a slow start shows where it is: the published port over localhost and 127.0.0.1, - # and the app inside its container. - if [ $((i % 6)) = 0 ]; then - v4=$(curl --connect-timeout 3 --max-time 5 -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:$port/api/health" || true) - echo "… ${SECONDS}s: replicas $replicas, health localhost ${health:-none} / 127.0.0.1 ${v4:-none} / inside $(inside)" - fi + # Progress, so a slow start shows where it is: the published port, and the app inside its + # container. + [ $((i % 6)) = 0 ] && echo "… ${SECONDS}s: replicas $replicas, health ${health:-none} / inside $(inside)" [ "$SECONDS" -ge "$deadline" ] && fail "the stack did not come up within 240 s (replicas $replicas, health ${health:-none})" sleep 3 done