Skip to content
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

the "distributed.worker" logger gains ~thousand DequeHandler instances during a pytest run #5973

Closed
graingert opened this issue Mar 21, 2022 · 2 comments · Fixed by #5985
Closed
Labels
bug Something is broken

Comments

@graingert
Copy link
Member

graingert commented Mar 21, 2022

running len(logging.getLogger("distributed.worker").handlers) shows a few thousand DequeHandler instances in there.
This means that logging messages from the worker or adding handlers to the worker gradually gets slower and slower as the test suite progresses.

the handlers are supposed to be cleared when the worker is GC'd by

weakref.finalize(self, logger.removeHandler, self._deque_handler)
however
@functools.lru_cache(None)
def _iscoroutinefunction_cached(f):
return _iscoroutinefunction(f)
def iscoroutinefunction(f):
# Attempt to use lru_cache version and fall back to non-cached version if needed
try:
return _iscoroutinefunction_cached(f)
except TypeError: # unhashable type
return _iscoroutinefunction(f)
keeps a permanent strong reference to the worker:

image

see #4481 and #4469

@graingert
Copy link
Member Author

the reference chain is from objgraph.find_backref_chain https://mg.pov.lt/objgraph/#memory-leak-example

@fjetter
Copy link
Member

fjetter commented Mar 21, 2022

If the performance problem is an actual concern, ensuring all handlers are async is probably the most straight forward and would resolve a few other issues around exception handling

some earlier and related work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants