direct_tls doesn't work with PostgreSQL 17+ because ALPN isn't set
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 76/100
調査の方向性
まず、asyncpg が direct_tls 用に作成する SSL コンテキストと、直接 SSL ネゴシエーションを処理する接続パスを特定します。Issue にある PostgreSQL 18 の Docker コマンドを使って再現し、その後、direct_tls 接続がデフォルトコンテキストで動作することを確認し、PostgreSQL の ALPN プロトコルのカバレッジを追加または更新します。
索引モデルが issue の本文から書いたものです。
説明
- 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.
- 主要言語
- Python
- スター
- 8.1k
- フォーク
- 469
- 平均マージ
- 4日 1時間
- マージ済み PR(30日)
- 14
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
MagicStack/asyncpg のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
MagicStack/asyncpg#1342 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 56/100
MagicStack/asyncpg#1340 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 28/100
MagicStack/asyncpg#1337 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
MagicStack/asyncpg#1330 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
MagicStack/asyncpg#1322 ·
MagicStack/asyncpg の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
stephrobert/dsoxlab#238 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
sublimehq/package_control#1780 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
nwg-piotr/nwg-displays#145 ·