Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#1,371 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
postgresql, python
領域
databases

調査の方向性

まず、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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

MagicStack/asyncpg のほかの issue

MagicStack/asyncpg の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。