getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.97k stars 1.57k forks source link

Sentry.captureException called in tight loop exhausted file handles #4485

Closed dougforster-at closed 2 years ago

dougforster-at commented 2 years ago

Package + Version

Version:

6.15.0

Description

We encountered a problem where:

  1. exceptions were thrown
  2. we caught them in a try/catch
  3. we called Sentry.captureException(err, sentryContext);
  4. this took place in a tight loop where many many exceptions were throw, caught and logged to Sentry

Result: the linux instance ran out file handles

We pinpointed https://github.com/getsentry/sentry-javascript/blob/8cbcff25235b8d67043820032dba7a9e9cae3a2a/packages/node/src/parsers.ts#L139 as the code that was opening the file handles.

We're interested to advocate for adding caching or enforcing a maximum number of open files, to avoid the risk of exhausting file handles on the host machine.

Thanks!

AbhiPrasad commented 2 years ago

Hey thanks for writing in!

We use an LRU cache to ensure that we cache calls to readFile, so it's interesting to see that this still happens.

https://github.com/getsentry/sentry-javascript/blob/8cbcff25235b8d67043820032dba7a9e9cae3a2a/packages/node/src/parsers.ts#L10

Perhaps we can add an additional check after the cache is full to check the file descriptor count.

Could you provide a link to your Sentry event or a copy of the event JSON (really we just need the exception object). That will help us start debugging and reproduce a test case!