GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add address hint to connect errors when PostgreSQL is unreachable by aryansk · Pull Request #1344 · MagicStack/asyncpg

Conversation

@aryansk

@aryansk aryansk commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

What

Fixes #1342 — when a connection attempt fails, the raised error now names the address that was tried, so a PostgreSQL server listening on a different port is distinguishable from a server that is not running.

Why

ConnectionRefusedError is byte-for-byte identical whether the server is down or simply listening elsewhere. The classic failure mode is connect(port=5433) against a server on 5432, or a wrong hostname — the error message gives no clue which address was actually attempted, and users assume PostgreSQL is broken instead of checking the port.

How

_connect() keeps the last attempted addr alongside the last error and, when re-raising, appends a hint:

[Errno 61] Connect call failed ('127.0.0.1', 5433) - verify that PostgreSQL is running and listening on 127.0.0.1:5433

The original exception is preserved as __cause__ and the same exception type is re-raised, so existing except OSError / except ConnectionRefusedError handling is unaffected. The TargetServerAttributeNotMatched branch (no OSError at all) is unchanged. Unix socket paths are formatted as path/.s.PGSQL.port, matching asyncpg's convention.

Tests

Added TestConnectErrorHint in tests/test_connect.py:

  • test_connect_error_includes_address_hint — a refused TCP connection reports 127.0.0.1:5432 in the message, and __cause__ is the original error (fails before the fix: message lacks the address).
  • test_connect_error_hint_for_unix_socket — a missing socket reports /var/run/postgresql/.s.PGSQL.5432 (fails before: message lacks the socket).

Both use unittest.mock.patch.object(connect_utils, '_connect_addr', ...) so they run without a live server. Full tests/test_connect.py suite passes.

🤖 Generated with Codebuff

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@aryansk @codebuff-team
Add address hint to connect errors when PostgreSQL is unreachable
4f9a26d
ConnectionRefusedError is identical whether the server is not running
or is simply listening on a different port. Include the attempted
address in the re-raised error so users can spot port mismatches
immediately instead of digging for the cause.

Fixes MagicStack#1342

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <[email protected]>
@aryansk aryansk mentioned this pull request Aug 16, 2026
[pr-relay] MagicStack/asyncpg #1342 aryansk/pr-relay#72
Open

This branch has not been deployed

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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Connect call failed error doesn't distinguish port mismatch from "server not running"

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@aryansk
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.