Skip to content
This repository was archived by the owner on Feb 15, 2026. It is now read-only.

Add timeout to PostgreSQL readiness check in docker-entrypoint.sh#4

Closed
Copilot wants to merge 4 commits intofeat/dockerfrom
copilot/sub-pr-2-again
Closed

Add timeout to PostgreSQL readiness check in docker-entrypoint.sh#4
Copilot wants to merge 4 commits intofeat/dockerfrom
copilot/sub-pr-2-again

Conversation

Copy link

Copilot AI commented Jan 29, 2026

The pg_isready check was waiting indefinitely for PostgreSQL without a timeout, causing containers to hang forever if the database never becomes available.

Changes:

  • Add configurable timeout via POSTGRES_MAX_RETRIES (default: 60) and POSTGRES_RETRY_DELAY (default: 1s)
  • Exit with clear error message after timeout, enabling orchestration systems to restart the container
  • Calculate total timeout as POSTGRES_MAX_RETRIES * POSTGRES_RETRY_DELAY for accuracy with custom delays

Implementation:

# Wait for PostgreSQL with timeout
POSTGRES_MAX_RETRIES="${POSTGRES_MAX_RETRIES:-60}"
POSTGRES_RETRY_DELAY="${POSTGRES_RETRY_DELAY:-1}"
POSTGRES_RETRY_COUNT=0

POSTGRES_TIMEOUT=$((POSTGRES_MAX_RETRIES * POSTGRES_RETRY_DELAY))
echo "Waiting for Postgres... (max ${POSTGRES_MAX_RETRIES} attempts, ${POSTGRES_TIMEOUT}s timeout)"
while ! pg_isready -h "${POSTGRESQL_HOST:-postgres}" -p "${POSTGRESQL_PORT:-5432}" -U "${POSTGRESQL_USER:-postgres}" >/dev/null 2>&1; do
  POSTGRES_RETRY_COUNT=$((POSTGRES_RETRY_COUNT + 1))

  if [ "$POSTGRES_RETRY_COUNT" -gt "$POSTGRES_MAX_RETRIES" ]; then
    echo "ERROR: PostgreSQL did not become available after ${POSTGRES_MAX_RETRIES} attempts (${POSTGRES_TIMEOUT}s timeout)"
    exit 1
  fi

  sleep "$POSTGRES_RETRY_DELAY"
done

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 29, 2026 12:02
Co-authored-by: 0ghost0-dev <70481054+0ghost0-dev@users.noreply.github.com>
Co-authored-by: 0ghost0-dev <70481054+0ghost0-dev@users.noreply.github.com>
Co-authored-by: 0ghost0-dev <70481054+0ghost0-dev@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on Feat/docker PR Add timeout to PostgreSQL readiness check in docker-entrypoint.sh Jan 29, 2026
Copilot AI requested a review from 0ghost0-dev January 29, 2026 12:07
Repository owner locked and limited conversation to collaborators Jan 29, 2026
@0ghost0-dev 0ghost0-dev deleted the copilot/sub-pr-2-again branch January 29, 2026 12:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants