Skip to content

Prestart script fails with multi-node DATABASE_URL #17

Description

@katrinajaneczko

While the app created with the template works with a DATABASE_URL like postgresql://USERNAME:PASSWORD@/DATABASE_NAME?host=HOST1,HOST2,HOST3&port=PORT1,PORT2,PORT3&target_session_attrs=primary, the prestart.sh script does not work correctly when DATABASE_URL contains multiple hosts (e.g., a Postgres URI with multiple nodes for HA/failover).

This is because the command

DB_HOST=$(python -c "from urllib.parse import urlparse; print(urlparse('${DATABASE_URL}').netloc.split('@')[-1]);")

returns the entire comma-separated host list (or empty value) and nc is then called with the whole comma-separated string as the hostname, causing the connection check to fail.

The script's host parsing logic should be updated to handle multiple hosts by parsing out the first available host from the URI and checking it, or loop over all nodes in the URI until one is reachable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions