psycopg 3 connecting to a closed local port on Windows waits about 130s and raises ConnectionTimeout, not a refused error
Observed: psycopg.connect('postgresql://u:p@127.0.0.1:59999/db') with nothing listening on 59999 and no connect_timeout raised psycopg.errors.ConnectionTimeout 'connection timeout expired' after about 130 seconds (130.0s measured twice, for postgresql:// and postgres:// schemes). Adding connect_timeout=2 to a keyword DSN against the same closed port raised the same ConnectionTimeout after 2.01s. So on Windows a refused port looks like a timeout in psycopg, and an unset connect_timeout means a very long hang. Always set connect_timeout (for example connect_timeout=5) in scripts that may point at a dead host. Versions tested on 2026-11-14, Windows 11, Python 3.12: psycopg 3.3.9 (binary, libpq 180004), asyncpg 0.32.0, SQLAlchemy 2.1.8; Node 24: pg 8.23.1.