From 55db4e85dbd7ecf7bf7d7020225274aec284f01d Mon Sep 17 00:00:00 2001 From: Molecule AI Core-DevOps Date: Thu, 14 May 2026 17:22:21 +0000 Subject: [PATCH] fix(ci): kill stale platform-server before binding port 8080 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit E2E API smoke test fails intermittently with: Server failed: listen tcp :8080: bind: address already in use Root cause: concurrent CI runs on the same host-network act_runner all bind the platform server to fixed port :8080. When a previous run is cancelled before the "Stop platform" step runs, its process lingers on :8080 and the new run fails to bind. Fix: add a pre-start step that probes :8080 and kills any stale platform-server via /proc scan. This is safe (no false positives — only kills if the port is actually in use) and requires no extra tools beyond curl+grep+kill which are universally available on Ubuntu/Debian runners. Refs: internal#374 Fixes: internal#374 Co-Authored-By: Claude Opus 4.7 --- .github/workflows/e2e-api.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/workflows/e2e-api.yml b/.github/workflows/e2e-api.yml index 7e783482..27f75100 100644 --- a/.github/workflows/e2e-api.yml +++ b/.github/workflows/e2e-api.yml @@ -242,6 +242,28 @@ jobs: if: needs.detect-changes.outputs.api == 'true' working-directory: workspace-server run: go build -o platform-server ./cmd/server + - name: Free port 8080 before start + if: needs.detect-changes.outputs.api == 'true' + run: | + # Kill any stale platform-server from a previous run that failed to + # clean up (e.g. runner was cancelled before the Stop step ran). + # Concurrent runs on the same host-network runner all bind :8080. + # Try curl first (cheap), kill if port is occupied. + if curl -sf http://127.0.0.1:8080/health > /dev/null 2>&1; then + echo "Port 8080 in use — killing stale platform-server" + # /proc scan — works on any Linux without pkill/lsof/ss. + # comm field is truncated to 15 chars: "platform-serve" matches. + # shellcheck disable=SC2013 + for pid in $(grep -l "platform-serve" /proc/[0-9]*/comm 2>/dev/null); do + kpid="${pid%/comm}" + kpid="${kpid##*/}" + echo "Killing stale process $kpid" + kill "$kpid" 2>/dev/null || true + done + sleep 2 # Wait for port to release. + else + echo "Port 8080 is free" + fi - name: Start platform (background) if: needs.detect-changes.outputs.api == 'true' working-directory: workspace-server