-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Sentry.captureException doesn't close readable stream opened by createReadStream in getContextLinesFromFile #14892
Comments
Removed Express from the reproducible example, It's a Sentry bug after all. |
The worst scenario happens if there's a loop doing captureException - it leads to same files being reopened & not closed. I.e. If we call captureException using an Express route it doesn't open extra files with subsequent HTTP requests, it only reads files once it seems. |
Hey @mstrokin thanks for the repro and PR! What version of node did you run the repro with? Want to see what test matrix to add to the PR. Assigning myself this issue, will try to update the PR tomorrow and get it merged in! |
Node v23.5.0 locally and Node v20 alpine on the server Tested it again on all of these, works the same everywhere. |
Also, fun fact that I didn't debug - if you move the code into a single file (i.e. move App code into main.ts) - it stops happening, I guess it already has a file in the memory in that case. |
I've debugged it a bit more and added new commit to repro repo, the bug is here - if we use lineReaded.removeAllListeners() it never closes the stream, not sure if it's a Node bug.
|
nodejs/node#9002 Node says it's not a bug |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
8.47.0
Framework Version
No response
Link to Sentry event
No response
Reproduction Example/SDK Setup
https://github.com/mstrokin/sentry-openfiles-bug
Steps to Reproduce
Running this in a Node Express server opens same files repeatedly without ever closing them, since 8.10.0 (8.9.0 works fine).
for (var i = 0; i < 1000; i++) {
Sentry.captureException('fake exception to test the files opening');
}
This is the cause of it: #12221
const stream = createReadStream(path);
this stream never gets closed (even though it supposed to use autoClose I think)
Expected Result
There are no open files in lsof output after sending the exceptions.
Actual Result
New files are opened every time captureException is called.
The text was updated successfully, but these errors were encountered: