forked from getsentry/sentry-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node): Allow Anr worker to be stopped and restarted (getsentry#1…
…1214) With the Electron SDK, we have an issue (getsentry/sentry-electron#830) where ANR causes the app to freeze when the machine goes through a suspend/resume cycle. This PR exposes `stopWorker` and `startWorker` methods which can be used in the downstream [ANR integration wrapper](https://github.com/getsentry/sentry-electron/blob/master/src/main/integrations/anr.ts) to stop the ANR feature before device suspend and start it again on device resume.
- Loading branch information
1 parent
d2a1e2a
commit 726d21e
Showing
3 changed files
with
109 additions
and
14 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
dev-packages/node-integration-tests/suites/anr/stop-and-start.js
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,50 @@ | ||
const crypto = require('crypto'); | ||
const assert = require('assert'); | ||
|
||
const Sentry = require('@sentry/node'); | ||
|
||
setTimeout(() => { | ||
process.exit(); | ||
}, 10000); | ||
|
||
const anr = Sentry.anrIntegration({ captureStackTrace: true, anrThreshold: 100 }); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
debug: true, | ||
autoSessionTracking: false, | ||
integrations: [anr], | ||
}); | ||
|
||
function longWorkIgnored() { | ||
for (let i = 0; i < 20; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512'); | ||
assert.ok(hash); | ||
} | ||
} | ||
|
||
function longWork() { | ||
for (let i = 0; i < 20; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512'); | ||
assert.ok(hash); | ||
} | ||
} | ||
|
||
setTimeout(() => { | ||
anr.stopWorker(); | ||
|
||
setTimeout(() => { | ||
longWorkIgnored(); | ||
|
||
setTimeout(() => { | ||
anr.startWorker(); | ||
|
||
setTimeout(() => { | ||
longWork(); | ||
}); | ||
}, 2000); | ||
}, 2000); | ||
}, 2000); |
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