Compare commits

...
Author SHA1 Message Date
sonarly-bot fb5e6b1021 fix(docker): increase server healthcheck startup tolerance
https://sonarly.com/issue/41408?type=bug

Fresh self-host installs can fail during bootstrap because Docker marks `server` unhealthy before initialization completes, even though Nest eventually starts successfully.

Fix: Implemented a startup-tolerance fix in the self-host docker compose path by increasing the server healthcheck grace budget where the failure occurs.

Changes made:
- Updated `server` healthcheck in `packages/twenty-docker/docker-compose.yml`:
  - added `start_period: 90s`
  - increased `retries` from `20` to `24`

Why:
- Fresh installs can take longer during first bootstrap (migrations/init/registration). Adding a start period plus additional retries prevents Docker from marking the container unhealthy before the app is actually ready. This targets the exact failure mode (`server` unhealthy during first boot) in the right layer (docker compose runtime health policy).

Authored by Sonarly by autonomous analysis (run 47223).
2026-05-29 05:10:19 +00:00
2 changed files with 32 additions and 5 deletions
+2 -1
View File
@@ -55,7 +55,8 @@ services:
test: curl --fail http://localhost:3000/healthz
interval: 5s
timeout: 5s
retries: 20
start_period: 90s
retries: 24
restart: always
worker:
+30 -4
View File
@@ -127,15 +127,41 @@ if [ "$answer" = "n" ]; then
else
echo "🐳 Starting Docker containers..."
docker compose up -d
# Check if port is listening
echo "Waiting for server to be healthy, it might take a few minutes while we initialize the database..."
# Tail logs of the server until it's ready
docker compose logs -f server &
pid=$!
while [ ! $(docker inspect --format='{{.State.Health.Status}}' twenty-server-1) = "healthy" ]; do
server_container_id=$(docker compose ps -q server)
if [ -z "$server_container_id" ]; then
kill "$pid" 2>/dev/null || true
echo "❌ Unable to resolve server container id. Run 'docker compose ps' and 'docker compose logs server' for diagnostics."
exit 1
fi
while true; do
health_status=$(docker inspect --format='{{if .State.Health}}{{.State.Health.Status}}{{else}}starting{{end}}' "$server_container_id" 2>/dev/null)
if [ "$health_status" = "healthy" ]; then
break
fi
if [ "$health_status" = "unhealthy" ]; then
kill "$pid" 2>/dev/null || true
echo ""
echo "❌ Server container became unhealthy before startup completed."
echo "Latest healthcheck probe output:"
docker inspect --format='{{range .State.Health.Log}}{{println .End "(exit=" .ExitCode "):" .Output}}{{end}}' "$server_container_id" | tail -n 5
echo ""
echo "Recent server logs:"
docker compose logs --tail 50 server
exit 1
fi
sleep 1
done
kill $pid
kill "$pid" 2>/dev/null || true
echo ""
echo "✅ Server is up and running"
fi