You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have encountered a memory leak issue when using PubNubAsyncio in our FastAPI application. The issue seems to be related to the creation and failure to release event loops after they are no longer needed.
Steps to Reproduce:
Create a PubNubAsyncio instance using asyncio.new_event_loop().
Use the PubNubAsyncio instance to publish messages.
Stop the PubNubAsyncio instance using await client.stop().
Observe that the created event loop is not released, leading to a memory leak.
After stopping the PubNubAsyncio instance using await client.stop(), the event loop created by asyncio.new_event_loop() is not released, causing a memory leak. Over time, this results in increased memory consumption.
Expected Behavior:
The event loop created by asyncio.new_event_loop() should be properly released when the PubNubAsyncio instance is stopped to prevent memory leaks.
Environment:
Python version: 3.12
PubNub version: 9.1.0
FastAPI version: 0.109.2
Additional Information:
We have observed this issue consistently in our production environment, leading to increased memory usage over time. Proper release of the event loop after stopping the PubNubAsyncio instance would help mitigate this issue.
The text was updated successfully, but these errors were encountered:
kimgunyoung
changed the title
**Title: Memory Leak in PubNubAsyncio due to Unreleased Event Loops**
Memory Leak in PubNubAsyncio due to Unreleased Event Loops
Mar 17, 2025
From my tests I see one big initial memory increase (related to imports) and after calling publish_message in a loop 100 times the increase is rather small (~1-2MB). Could you provide more information about use case, like how long the script is running, how many iteration is done and how is the memory usage measured?
After further investigation, I found that explicitly setting enable_subscribe = False in the PNConfiguration resolved the issue. It appears that the unreleased event loop was related to the subscribe mechanism being enabled by default.
Apologies for the confusion, and thank you again for your support. I’ll go ahead and close this issue now.
Description:
We have encountered a memory leak issue when using
PubNubAsyncio
in our FastAPI application. The issue seems to be related to the creation and failure to release event loops after they are no longer needed.Steps to Reproduce:
PubNubAsyncio
instance usingasyncio.new_event_loop()
.PubNubAsyncio
instance to publish messages.PubNubAsyncio
instance usingawait client.stop()
.Code Example:
Observed Behavior:
After stopping the
PubNubAsyncio
instance usingawait client.stop()
, the event loop created byasyncio.new_event_loop()
is not released, causing a memory leak. Over time, this results in increased memory consumption.Expected Behavior:
The event loop created by
asyncio.new_event_loop()
should be properly released when thePubNubAsyncio
instance is stopped to prevent memory leaks.Environment:
Additional Information:
We have observed this issue consistently in our production environment, leading to increased memory usage over time. Proper release of the event loop after stopping the
PubNubAsyncio
instance would help mitigate this issue.The text was updated successfully, but these errors were encountered: