-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sdk): work around memory leak with recursive SDK usage
This works around a memory issue with a specific SKD usage pattern, namely when SDK entry spans are created while the previous async context (AsyncLocalStorage or cls-hooked) is still active. Since new context objects are connected to the previously active context via prototypical inheritance (that is, they are created via Object.create(activeContext)), this pattern would create an ever-growing chain of contexts which reference their predecessor context via .__proto__. Since the most recent/currently active context is referenced by us, and all other contexts are referenced by their successor, none of the context objects can be garbage collected. Thus, this usage pattern effectively results in memory leak. In turn, that memory leak caused major GCs increasingly often, which in turn take increasingly longer, because the garbage collector needs to walk increasingly longer chains of context objects connected by their prototype reference. There is a more detailed internal analysis available at https://www.notion.so/instana/SDK-Memory-Leak-a807a1b242c84976ac79d9a1a9037494 refs 106899
- Loading branch information
Showing
4 changed files
with
52 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters