Playing Minesweeper with Asyncpg
summary
A Rambler&Co engineer describes a hard-to-reproduce memory-leak caused by asyncpg connections that became permanently stuck in the connection pool, leading to leaked shared-memory allocations in Postgres. The talk explains how they investigated the issue by attaching gdb to a live production Python process (with PYTHONOPTIMIZE), inspecting the Python garbage collector to find leaking objects, and ultimately fixed it by forcibly killing and recreating connections, while not finding the library root cause. It covers practical debugging techniques using gdb and Python’s gc module for asyncio/python/postgres/asyncpg users and ops who must debug running production services.
AI-written summary · about
chapters (18)
- 0:00Introduction
- 0:26Memory leak problem
- 2:19Data server shared memory
- 3:42Memory leak symptoms
- 5:07Investigating issue
- 9:01Debugging challenges
- 12:55Debugging production
- 14:43GDB for Python
- 18:39Root cause found
- 21:30Process object analysis
- 22:35Object reference tracing
- 24:20Timeout errors cause
- 26:27Asyncpg connection pool
- 29:15Connection hang detection
- 31:03Python bug suspected
- 32:06Final solution
- 33:09Tool motivation
- 33:53Q&A
