-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(node): Enforce that ContextLines integration does not leave open …
…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.
- Loading branch information
1 parent
1f0958f
commit 9f74bc9
Showing
12 changed files
with
290 additions
and
5 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...gration-tests/suites/contextLines/test.ts → ...contextLines/filename-with-spaces/test.ts
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
5 changes: 5 additions & 0 deletions
5
dev-packages/node-integration-tests/suites/contextLines/memory-leak/nested-file.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as Sentry from '@sentry/node'; | ||
|
||
export function captureException(i: number): void { | ||
Sentry.captureException(new Error(`error in loop ${i}`)); | ||
} |
7 changes: 7 additions & 0 deletions
7
dev-packages/node-integration-tests/suites/contextLines/memory-leak/other-file.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { captureException } from './nested-file'; | ||
|
||
export function runSentry(): void { | ||
for (let i = 0; i < 10; i++) { | ||
captureException(i); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
dev-packages/node-integration-tests/suites/contextLines/memory-leak/scenario.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { execSync } from 'node:child_process'; | ||
import * as path from 'node:path'; | ||
|
||
import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
transport: loggingTransport, | ||
}); | ||
|
||
import { runSentry } from './other-file'; | ||
|
||
runSentry(); | ||
|
||
const lsofOutput = execSync(`lsof -p ${process.pid}`, { encoding: 'utf8' }); | ||
const lsofTable = lsofOutput.split('\n'); | ||
const mainPath = __dirname.replace(`${path.sep}suites${path.sep}contextLines${path.sep}memory-leak`, ''); | ||
const numberOfLsofEntriesWithMainPath = lsofTable.filter(entry => entry.includes(mainPath)); | ||
|
||
// There should only be a single entry with the main path, otherwise we are leaking file handles from the | ||
// context lines integration. | ||
if (numberOfLsofEntriesWithMainPath.length > 1) { | ||
// eslint-disable-next-line no-console | ||
console.error('Leaked file handles detected'); | ||
// eslint-disable-next-line no-console | ||
console.error(lsofTable); | ||
process.exit(1); | ||
} |
16 changes: 16 additions & 0 deletions
16
dev-packages/node-integration-tests/suites/contextLines/memory-leak/test.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
||
describe('ContextLines integration in CJS', () => { | ||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
// Regression test for: https://github.com/getsentry/sentry-javascript/issues/14892 | ||
test('does not leak open file handles', done => { | ||
createRunner(__dirname, 'scenario.ts') | ||
.expectN(10, { | ||
event: {}, | ||
}) | ||
.start(done); | ||
}); | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
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