robs_awesome_python_template icon indicating copy to clipboard operation
robs_awesome_python_template copied to clipboard

Prestart script fails with multi-node DATABASE_URL

Open katrinajaneczko opened this issue 5 months ago • 0 comments

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.

katrinajaneczko avatar Sep 12 '25 13:09 katrinajaneczko