opentelemetry-js: Harden AsyncHooksScopeManager regarding faulty use of AsyncResources

Is your feature request related to a problem? Please describe. Some libraries may implement misbehaving AsyncResources for which the destroy callback won’t be ever called. This would result in a memory leak in AsyncHooksScopeManager as the corresponding entry is never deleted from _scopes. Even the problem/bug is actually in the faulty use of AsyncResources the leak may only appear if OTel is used in such an application.

inspired by https://github.com/nodejs/node/pull/26540#discussion_r349906661

Describe the solution you’d like Add some counter measures to detect such leaks and do a cleanup of old/outdated entries.

Describe alternatives you’ve considered Only document that memory leaks like this could happen but root cause is somewhere else and needs to be handled somewhere else.

Additional context I think this is more a discussion then a feature request but there exists on discussion type for issues and my feeling is that feature request fits better then bug.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

Yes, I actually wanted to work on that today 😂

I really want #1040 to be done. I started work on it once before but got busy doing other things. If you want it @michaelgoin comment on the issue and i’ll assign you.

I think that makes sense. Some of the benefit comes from what I was mentioning above but beyond that… using what is hoped as the future of such context tracking for Node would potentially have mutual benefit for this project and Node.

You’re welcome to take a shot 😃