MagicStack / MagicStack/asyncpg
How are Postgres server restarts handled?
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 8.1k
- 分支
- 468
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Hi guys,
We are using asyncpg in a web application.
Upon starting the web server, we do the following two things:
db = asyncpg.create_poolto create the connection pool for the application's DB connections.conn = await db.pool.acquire(); await conn.add_listener('foo', _callback)to register long-lived listeners to catch and handleNOTIFYevents from the DB.
Recently I restarted the Postgres server and noticed something interesting. First, connections to the DB using the db pool object saw no interruption and were still able to connect to the DB server despite it having a new PID (since the process had been restarted).
However, the conn the application relied on to receive async notifications from the server was dead/closed and so the application logic dependent upon receiving those notifications was not functioning. (This is how I reproduced this issue and discovered the cause to have been a PG server restart.)
- Why is the pool unaffected by restart? It makes sense the connection instance is dead since the socket is closed after restarting the server, but I'm a bit surprised the pool is not affected.
- I suppose the best strategy for checking for dead DB connections would be to simply check
conn.is_closedperiodically - or, is there some "on connection close" callback I can define to retry/reopen a connection (since obtaining new connections from the pool still works after restart)?
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先查看報告中描述的 asyncpg.create_pool、pool.acquire、add_listener 和 conn.is_closed 進入點,以及伺服器重新啟動期間 PostgreSQL NOTIFY 的行為。確定池化連線和長期執行的監聽器應如何運作,並記錄偵測和復原已關閉監聽器連線的受支援方式。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- postgresql, python
- 領域
- backend, databases
- Issue 類型
- 文件
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 25/100