-
-
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
open handle in @sentry/node v6.9.0 #3827
Comments
Could you provide the logs from jest? Just to get some context, why are you initing Sentry in your tests? Does the issue still persist if you set |
I encountered the same issue, and the only two solution I found that solved the problem were:
When using Jest’s
Constructor code referenced by the stack trace: sentry-javascript/packages/hub/src/sessionflusher.ts Lines 28 to 33 in ba7ca16
…so that makes the above solutions make sense and the issue relatively clear. Nothing ever stops the While the solutions I came up with work, it doesn’t seem great that simply including Sentry in a test (especially when
|
(If you’re following along in e-mail, I updated the above with the actual stack trace from Jest, which I forgot to paste originally.) |
Edit: I figured this out — the SDK detects the value for sentry-javascript/packages/node/src/sdk.ts Lines 103 to 111 in ba7ca16
|
Appreciate the detailed repro + stack trace, thank you!
sentry-javascript/packages/node/src/handlers.ts Lines 385 to 386 in ba7ca16
Also, @Mr0grog would love to get more insight into why you are running Sentry in tests vs. just mocking it out à la: jest.mock('@sentry/node', () => {
const SentryNode = jest.requireActual('@sentry/node');
return {
init: jest.fn(),
configureScope: jest.fn(),
setTag: jest.fn(),
setExtra: jest.fn(),
// ...
};
}); |
Ah, to be clear, that works! (As in: it does successfully prevent creation of the session flusher and resolves the issue with tests hanging.) The issue for me was that the change of the default in 6.9.0 was a surprising breaking change, and that, in the past, the defaults have not created a situation where Sentry needs special treatment when shutting my program down. Now they do.
To be honest, I just leave it as-is in tests for most projects, since in the vast majority of cases, it runs in the test environment with no Any mock I set up also has to be constantly updated to keep in sync with Sentry’s API, and while Jest offers some useful auto-mocking tools there, it’s never perfect. Checking the mocks on every update is a lot of overhead when the release cadence of Sentry is every couple weeks. So in most cases, it’s preferable not to mock it. |
(Also it was surprising that the default for |
This has been addressed with #3954 and should be available with the next release. If you have any other feedback, please let us know - it is highly appreciated. |
Package + Version
@sentry/browser
@sentry/node
raven-js
raven-node
(raven for node)Version:
node.js version v16.5.0
Description
v6.9.0 introduced an open handle when running with jest tests.
I was able to pin down the commit causing the issue: #3758
also tried the latest next version (6.10.0-beta.3). issue still persists.
The text was updated successfully, but these errors were encountered: