Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ version: 1
platform: python
platformVersion: "3.14"
run:
port: 8080
port: 8080
startCommand: "bash /output/flaky-startup.sh"
41 changes: 41 additions & 0 deletions flaky-startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
set +e
TAG="${EMBR_DEPLOYMENT_ID:-unknown}"
echo "[healthy-startup ${TAG}] starting at $(date -u)"
echo "[healthy-startup ${TAG}] PID=$$, PPID=$PPID"
echo "[healthy-startup ${TAG}] ports in use BEFORE bind:"
ss -ltnp 2>&1 | grep -E ':8080|LISTEN' | head -10
echo "[healthy-startup ${TAG}] my parent process tree:"
ps -ef --forest 2>&1 | head -30

python -c "
import socket, sys, time, os
print(f'[healthy-startup {os.environ.get(\"EMBR_DEPLOYMENT_ID\",\"?\")}] attempting bind on :8080', flush=True)
attempts = 0
while attempts < 30:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
s.bind(('0.0.0.0', 8080))
s.listen(8)
print(f'[healthy-startup {os.environ.get(\"EMBR_DEPLOYMENT_ID\",\"?\")}] BOUND :8080 successfully after {attempts} attempts', flush=True)
break
except OSError as e:
attempts += 1
print(f'[healthy-startup {os.environ.get(\"EMBR_DEPLOYMENT_ID\",\"?\")}] BIND FAILED attempt {attempts}: {e}', flush=True)
s.close()
time.sleep(1)
else:
print(f'[healthy-startup {os.environ.get(\"EMBR_DEPLOYMENT_ID\",\"?\")}] GAVE UP after 30 attempts', flush=True)
sys.exit(98)
print(f'[healthy-startup {os.environ.get(\"EMBR_DEPLOYMENT_ID\",\"?\")}] serving forever now', flush=True)
# minimal HTTP responder
from http.server import HTTPServer, BaseHTTPRequestHandler
class H(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200); self.end_headers(); self.wfile.write(b'ok')
def log_message(self, *a): pass
HTTPServer.allow_reuse_address = True
HTTPServer(('0.0.0.0', 8080), H, bind_and_activate=False).serve_forever()
" || true
sleep 60