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

fix(node): Enforce that ContextLines integration does not leave open file handles #14995

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Jan 13, 2025

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 alongside child_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.

@AbhiPrasad AbhiPrasad force-pushed the abhi-context-lines-stream-handle branch from 58c4a76 to 11c8d04 Compare January 13, 2025 22:13
Copy link
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.01 KB - -
@sentry/browser - with treeshaking flags 21.68 KB - -
@sentry/browser (incl. Tracing) 35.52 KB - -
@sentry/browser (incl. Tracing, Replay) 72.3 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 62.82 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 76.56 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 88.57 KB - -
@sentry/browser (incl. Feedback) 39.23 KB - -
@sentry/browser (incl. sendFeedback) 27.64 KB - -
@sentry/browser (incl. FeedbackAsync) 32.41 KB - -
@sentry/react 25.71 KB - -
@sentry/react (incl. Tracing) 38.3 KB - -
@sentry/vue 27.11 KB - -
@sentry/vue (incl. Tracing) 37.26 KB - -
@sentry/svelte 23.13 KB - -
CDN Bundle 24.28 KB - -
CDN Bundle (incl. Tracing) 35.83 KB - -
CDN Bundle (incl. Tracing, Replay) 70.47 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 75.63 KB - -
CDN Bundle - uncompressed 70.78 KB - -
CDN Bundle (incl. Tracing) - uncompressed 106.06 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 216.88 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 229.42 KB - -
@sentry/nextjs (client) 38.41 KB - -
@sentry/sveltekit (client) 36.06 KB - -
@sentry/node 161.46 KB +0.01% +15 B 🔺
@sentry/node - without tracing 97.26 KB +0.02% +16 B 🔺
@sentry/aws-serverless 127.12 KB +0.02% +16 B 🔺

View base workflow run

@AbhiPrasad AbhiPrasad merged commit 9f74bc9 into develop Jan 14, 2025
109 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-context-lines-stream-handle branch January 14, 2025 03:16
AbhiPrasad added a commit that referenced this pull request Jan 14, 2025
…file handles (#14995)

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.
AbhiPrasad added a commit that referenced this pull request Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sentry.captureException doesn't close readable stream opened by createReadStream in getContextLinesFromFile
2 participants