-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Potential memory leak #7
Comments
contents of this may be useful |
Thanks for bringing this to my attention! Went through the link you provided above, and one of the references: It doesn't seem like a memory leak can occur even if |
Your PR #8 will change the intended behaviour of the event processing. If both |
perhaps, a nested try block would be a safe approach here? |
Though, I'm really curious to perform some sort of tests to verify both of our hypothesis |
it should either rely on the garbage collector and does not care about context var reset at all, or come up with a robust context var management technique |
Yes, a nested |
I agree with you, since we're using |
here's an example inspired by loguru's logger @contextlib.contextmanager
def contextualize():
token = context.set(deque())
try:
yield
finally:
context.reset(token) and then use this context manager in the middleware |
I like this solution, we can potentially do:
|
yeah, something like that |
Feel free to use a context manager. If not, we can stick to the nested try block for now. Again, thanks for your contribution! |
I've updated pull request |
fastapi-events/fastapi_events/middleware.py
Lines 23 to 28 in a5a2823
If
await self._process_events()
raises an exception thenevent_store.reset(token)
does not happen.The text was updated successfully, but these errors were encountered: