hundreds-river-86592
11/10/2025, 10:41 AMliblivekit_ffi.so) during stress testing of our audio bridge service.
Environment:
• LiveKit Python SDK (FFI-based)
• Use case: WebSocket audio bridge mediating streams between Vonage and LiveKit
• Load pattern: Multiple concurrent short-duration calls
Symptoms:
• Steady RSS growth (~18% after 100 calls) with no corresponding Python heap increase
• tracemalloc shows stable heap usage (~6.8% growth, expected)
• /proc/self/smaps analysis confirms growth in native allocations under liblivekit_ffi.so (+2.4 MB) and Python interpreter (+13 MB)
• Memory is not released after room teardown
What we've ruled out:
• ✅ Python-level circular references (fixed by deregistering event handlers)
• ✅ Python object retention (verified with gc.get_referrers())
• ✅ File descriptors, asyncio tasks, sockets (all stable)
Conclusion:
The leak originates in the C/C++ FFI bridge, likely in audio buffer or network-related allocations that persist beyond room lifetime. No Python-side mitigation is possible without an explicit native resource release API.tall-airline-16756
11/10/2025, 10:41 AMtall-airline-16756
11/10/2025, 10:41 AMliblivekit_ffi.so), here are some friendly steps you can follow to investigate and hopefully ease the issue:
1. Try enabling debug logging by setting LIVEKIT_RTC_DEBUG=1. This will give you detailed logs from the FFI layer, including WebRTC and LiveKit components, which can be really insightful.
2. Make sure that all SDK objects like tracks, rooms, and publishers are properly cleaned up in your application code, especially when things get busy. The FfiHandle class is designed to explicitly release resources, so double-check that all handles are being disposed of correctly.
3. Consider using external memory profiling tools such as pympler, tracemalloc, or valgrind (with Python debug symbols) to keep an eye on memory allocations and spot any growth patterns during long or heavy sessions.
4. Also, please confirm you’re running the latest version of the LiveKit Python SDK, since recent updates often include improvements to memory management.
To dig a little deeper and assist you better, it would be great if you could share:
• The exact version of the LiveKit Python SDK you’re using (pip freeze | grep livekit)
• Your Python version (python --version)
• A minimal reproducible example that shows the leak under stress conditions
• Logs captured with LIVEKIT_RTC_DEBUG=1 enabled
• Any stack traces or memory usage graphs you’ve noticed during your testing
With these details, we’ll be in a much better position to pinpoint the root cause and explore the best fixes together. Please don’t hesitate to reach out with any questions along the way — I’m here to help!
Sources: .github/workflows/ffi-builds.yml | Still Have Questions | livekit-rtc/livekit/rtc/_proto/ffi_pb2.pyihundreds-river-86592
11/10/2025, 10:56 AMtall-airline-16756
11/10/2025, 10:56 AMhundreds-river-86592
11/10/2025, 10:58 AMtall-airline-16756
11/10/2025, 10:58 AM