BlogsLyftPython Memory Leak Debugging and Mitigation

Python Memory Leak Debugging and Mitigation

Python Memory Leak Debugging and Mitigation

1
posts
2025

Lyft engineers encountered and resolved a memory leak during a Python version upgrade from 3.8 to 3.10. The issue manifested as increased latency and frequent container restarts. The investigation involved using a custom memory profiling tool based on tracemalloc and identifying an incompatibility between gevent's monkey patching and urllib3's connection pooling, specifically related to weakref.finalize. Downgrading urllib3 to 1.26.15 resolved the issue. The post also details challenges with gunicorn's preload setting when using signals for debugging.

2025

From Python3.8 to Python3.10: Our Journey Through a Memory Leak

12/15/2025

This post details the debugging process for a memory leak in a Python service after upgrading from 3.8 to 3.10. It highlights the use of a custom tracemalloc-based memory profiler, the impact of gunicorn's preload setting on signal handling, and the root cause identified as an incompatibility between gevent and urllib3 (v1.26.16) leading to connection pool exhaustion. The solution involved downgrading urllib3 to v1.26.15.