Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

direct_tls doesn't work with PostgreSQL 17+ because ALPN isn't set

Offen Anfängerfreundlich
#1,371 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
76/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
postgresql, python
Bereich
databases

Rechercherichtung

Beginne damit, die SSL-Kontexte zu lokalisieren, die asyncpg für direct_tls erstellt, sowie den Verbindungspfad, der die direkte SSL-Aushandlung verarbeitet. Reproduziere mit dem PostgreSQL-18-Docker-Befehl aus dem Issue und überprüfe anschließend, dass Verbindungen mit direct_tls mit dem Standardkontext funktionieren, und füge Abdeckung für das PostgreSQL-ALPN-Protokoll hinzu oder aktualisiere sie.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

  • asyncpg version: 0.31.0 (also checked master)
  • PostgreSQL version: 17.11 and 18.0
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : No, reproduced with a local PostgreSQL in Docker
  • Python version: 3.12
  • Platform: Linux
  • Do you use pgbouncer?: No
  • Did you install asyncpg with pip?: Yes (via uv)
  • If you built asyncpg locally, which version of Cython did you use?: N/A
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : Only tried asyncio

When connecting with direct_tls=True, the connection gets dropped right away:

await asyncpg.connect(dsn, ssl="require", direct_tls=True)
# ConnectionDoesNotExistError: connection was closed in the middle of operation

The server log says why:

LOG:  received direct SSL connection request without ALPN protocol negotiation extension

PostgreSQL 17 requires the postgresql ALPN protocol for direct SSL connections, and libpq always sends it. asyncpg doesn't set ALPN on the context it builds, so as far as I can tell direct_tls (and sslnegotiation=direct in the DSN) can't work against a stock PG 17+ server unless you pass your own context:

ctx = ssl.create_default_context()
ctx.set_alpn_protocols(["postgresql"])
await asyncpg.connect(dsn, ssl=ctx, direct_tls=True)  # works

Repro with Docker:

docker run --rm -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres:18 \
  -c ssl=on \
  -c ssl_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem \
  -c ssl_key_file=/etc/ssl/private/ssl-cert-snakeoil.key

I'll send a PR that sets postgresql ALPN on the contexts asyncpg creates.

Vorherrschende Sprache
Python
Sterne
8.1k
Forks
469
Ø Merge
4 T. 1 Std.
Gemergte PRs (30 T.)
14

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus MagicStack/asyncpg

Alle Issues in MagicStack/asyncpg

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.