Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉 適合新手
#1,371 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
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 小時
30 天內合併 PR
14

貢獻指南

這個儲存庫沒有索引到貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

MagicStack/asyncpg 的其他 Issue

查看 MagicStack/asyncpg 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。