elastic / elastic/apm-agent-nodejs
Avoid Leaking under Jest
- Dominant language
- JavaScript
- Stars
- 594
- Forks
- 244
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 16
Description
We've received reports that's the agent will leak when used inside the [jest testing framework](https://jestjs.io/). This is a [known issue with jest and modules that employ some form of redefining modules/monkey-patching](https://chanind.github.io/javascript/2019/10/12/jest-tests-memory-leak.html).
It would good to better understand what jest is doing, how that interacts poorly with other modules redefining things, and determine if there's any proactive steps we can take to detect jest and avoid the leaks.
**Other Data Points**
- Issue [in jest repo](https://github.com/facebook/jest/issues/6814)
- [Kibana issue](https://github.com/elastic/kibana/issues/117255) that led to this discovery
From @pgayvallet
> During my testing, I observed that just importing the agent once did not seem to cause a leak. It had to be imported twice from two distinct paths of the test's dependency tree to start leaking (e.g A-B-C-agent and A-D-C-agent)
**Proposed Next Steps:**
- [ ] reproduce issue in isolation
- [ ] determine what jest is doing and why that leads to leaking
- [ ] if possible, take proactive steps to avoid leaking
Contributor guide
Assessment
This issue has not been assessed yet.