fix(node): Enforce that ContextLines integration does not leave open file handles #14995
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Supercedes #14893
resolves #14892
Thanks to @mstrokin for the fix! Left you a changelog highlight.
The ContextLines integration uses readable streams to more memory efficiently read files that it uses to attach source context to outgoing events. See more details here: #12221
Unfortunately, if we don't explicitly destroy the stream after creating and using it, it won't get closed, even when we remove the readline interface that uses the stream (which actual does the reading of files).
To fix this, we adjust the resolve logic when getting file context to destroy the stream, as we anyway are done with the readline interface.
I attached a test that uses
lsof
alongsidechild_process.execSync
to check for file handles, which is how @mstrokin was able to repro this for us: https://github.com/mstrokin/sentry-openfiles-bug. I tried a couple other approaches but wasn't too happy with it, so settled with this. Let me know if you think there's a better way.