Handle corner cases correctly in psql's reconnection logic