Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as Sentry from '@sentry/node-core';
import * as assert from 'assert';
import * as crypto from 'crypto';
import * as path from 'path';
import * as url from 'url';
import { setupOtel } from '../../utils/setupOtel.js';
Expand All @@ -26,11 +24,16 @@ Sentry.setUser({ email: 'person@home.com' });
Sentry.addBreadcrumb({ message: 'important message!' });

function longWork() {
for (let i = 0; i < 50; i++) {
const salt = crypto.randomBytes(128).toString('base64');
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
assert.ok(hash);
// Busy-block the event loop with pure-JS work. The ANR worker samples the main thread via the
// inspector, which can only pause at a JS safepoint; inside a native call like `crypto.pbkdf2Sync`
// the pause resolves only after the call returns, so the sample can miss `longWork` and land in
// timer internals instead. Pure-JS work keeps `longWork` on the sampled stack for the whole block.
const start = Date.now();
let n = 1;
while (Date.now() - start < 1000) {
n = (n * 1103515245 + 12345) % 2147483648;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This math seems kind of silly? It's not significantly different than just n++, since it's going to run about 35M times in a second, regardless. The more costly work is just the Date.now() check.

}
return n;
}

waitForDebuggerReady(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as Sentry from '@sentry/node-core';
import * as assert from 'assert';
import * as crypto from 'crypto';
import { setupOtel } from '../../utils/setupOtel.js';
import { waitForDebuggerReady } from '@sentry-internal/test-utils';

Expand All @@ -22,11 +20,16 @@ Sentry.setUser({ email: 'person@home.com' });
Sentry.addBreadcrumb({ message: 'important message!' });

function longWork() {
for (let i = 0; i < 50; i++) {
const salt = crypto.randomBytes(128).toString('base64');
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
assert.ok(hash);
// Busy-block the event loop with pure-JS work. The ANR worker samples the main thread via the
// inspector, which can only pause at a JS safepoint; inside a native call like `crypto.pbkdf2Sync`
// the pause resolves only after the call returns, so the sample can miss `longWork` and land in
// timer internals instead. Pure-JS work keeps `longWork` on the sampled stack for the whole block.
const start = Date.now();
let n = 1;
while (Date.now() - start < 1000) {
n = (n * 1103515245 + 12345) % 2147483648;
}
return n;
}

waitForDebuggerReady(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
const crypto = require('crypto');
const assert = require('assert');

const Sentry = require('@sentry/node-core');
const { setupOtel } = require('../../utils/setupOtel.js');
const { waitForDebuggerReady } = require('@sentry-internal/test-utils');
Expand All @@ -21,11 +18,16 @@ Sentry.setUser({ email: 'person@home.com' });
Sentry.addBreadcrumb({ message: 'important message!' });

function longWork() {
for (let i = 0; i < 50; i++) {
const salt = crypto.randomBytes(128).toString('base64');
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
assert.ok(hash);
// Busy-block the event loop with pure-JS work. The ANR worker samples the main thread via the
// inspector, which can only pause at a JS safepoint; inside a native call like `crypto.pbkdf2Sync`
// the pause resolves only after the call returns, so the sample can miss `longWork` and land in
// timer internals instead. Pure-JS work keeps `longWork` on the sampled stack for the whole block.
const start = Date.now();
let n = 1;
while (Date.now() - start < 1000) {
n = (n * 1103515245 + 12345) % 2147483648;
}
return n;
}

waitForDebuggerReady(() => {
Expand Down
16 changes: 9 additions & 7 deletions dev-packages/node-core-integration-tests/suites/anr/basic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
const crypto = require('crypto');
const assert = require('assert');

const Sentry = require('@sentry/node-core');
const { setupOtel } = require('../../utils/setupOtel.js');
const { waitForDebuggerReady } = require('@sentry-internal/test-utils');
Expand All @@ -23,11 +20,16 @@ Sentry.setUser({ email: 'person@home.com' });
Sentry.addBreadcrumb({ message: 'important message!' });

function longWork() {
for (let i = 0; i < 50; i++) {
const salt = crypto.randomBytes(128).toString('base64');
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
assert.ok(hash);
// Busy-block the event loop with pure-JS work. The ANR worker samples the main thread via the
// inspector, which can only pause at a JS safepoint; inside a native call like `crypto.pbkdf2Sync`
// the pause resolves only after the call returns, so the sample can miss `longWork` and land in
// timer internals instead. Pure-JS work keeps `longWork` on the sampled stack for the whole block.
const start = Date.now();
let n = 1;
while (Date.now() - start < 1000) {
n = (n * 1103515245 + 12345) % 2147483648;
}
return n;
}

waitForDebuggerReady(() => {
Expand Down
15 changes: 9 additions & 6 deletions dev-packages/node-core-integration-tests/suites/anr/basic.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as Sentry from '@sentry/node-core';
import * as assert from 'assert';
import * as crypto from 'crypto';
import { setupOtel } from '../../utils/setupOtel.js';
import { waitForDebuggerReady } from '@sentry-internal/test-utils';

Expand All @@ -22,11 +20,16 @@ Sentry.setUser({ email: 'person@home.com' });
Sentry.addBreadcrumb({ message: 'important message!' });

function longWork() {
for (let i = 0; i < 50; i++) {
const salt = crypto.randomBytes(128).toString('base64');
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
assert.ok(hash);
// Busy-block the event loop with pure-JS work. The ANR worker samples the main thread via the
// inspector, which can only pause at a JS safepoint; inside a native call like `crypto.pbkdf2Sync`
// the pause resolves only after the call returns, so the sample can miss `longWork` and land in
// timer internals instead. Pure-JS work keeps `longWork` on the sampled stack for the whole block.
const start = Date.now();
let n = 1;
while (Date.now() - start < 1000) {
n = (n * 1103515245 + 12345) % 2147483648;
}
return n;
}

waitForDebuggerReady(() => {
Expand Down
16 changes: 9 additions & 7 deletions dev-packages/node-core-integration-tests/suites/anr/forked.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
const crypto = require('crypto');
const assert = require('assert');

const Sentry = require('@sentry/node-core');
const { setupOtel } = require('../../utils/setupOtel.js');
const { waitForDebuggerReady } = require('@sentry-internal/test-utils');
Expand All @@ -22,11 +19,16 @@ Sentry.setUser({ email: 'person@home.com' });
Sentry.addBreadcrumb({ message: 'important message!' });

function longWork() {
for (let i = 0; i < 50; i++) {
const salt = crypto.randomBytes(128).toString('base64');
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
assert.ok(hash);
// Busy-block the event loop with pure-JS work. The ANR worker samples the main thread via the
// inspector, which can only pause at a JS safepoint; inside a native call like `crypto.pbkdf2Sync`
// the pause resolves only after the call returns, so the sample can miss `longWork` and land in
// timer internals instead. Pure-JS work keeps `longWork` on the sampled stack for the whole block.
const start = Date.now();
let n = 1;
while (Date.now() - start < 1000) {
n = (n * 1103515245 + 12345) % 2147483648;
}
return n;
}

waitForDebuggerReady(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as Sentry from '@sentry/node-core';
import * as assert from 'assert';
import * as crypto from 'crypto';
import { setupOtel } from '../../utils/setupOtel.js';
import { waitForDebuggerReady } from '@sentry-internal/test-utils';

Expand All @@ -20,12 +18,11 @@ Sentry.setUser({ email: 'person@home.com' });
Sentry.addBreadcrumb({ message: 'important message!' });

function longWork() {
// This loop will run almost indefinitely
let n = 1;
for (let i = 0; i < 2000000000; i++) {
const salt = crypto.randomBytes(128).toString('base64');
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
assert.ok(hash);
n = (n * 1103515245 + 12345) % 2147483648;
}
return n;
}

waitForDebuggerReady(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as Sentry from '@sentry/node-core';
import * as assert from 'assert';
import * as crypto from 'crypto';
import { setupOtel } from '../../utils/setupOtel.js';

setTimeout(() => {
Expand All @@ -18,11 +16,16 @@ setupOtel(client);
async function longWork() {
await new Promise(resolve => setTimeout(resolve, 1000));

for (let i = 0; i < 50; i++) {
const salt = crypto.randomBytes(128).toString('base64');
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
assert.ok(hash);
// Busy-block the event loop with pure-JS work. The ANR worker samples the main thread via the
// inspector, which can only pause at a JS safepoint; inside a native call like `crypto.pbkdf2Sync`
// the pause resolves only after the call returns, so the sample can miss `longWork` and land in
// timer internals instead. Pure-JS work keeps `longWork` on the sampled stack for the whole block.
const start = Date.now();
let n = 1;
while (Date.now() - start < 1000) {
n = (n * 1103515245 + 12345) % 2147483648;
}
return n;
}

function neverResolve() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
const crypto = require('crypto');
const assert = require('assert');

const Sentry = require('@sentry/node-core');
const { setupOtel } = require('../../utils/setupOtel.js');

Expand All @@ -23,19 +20,29 @@ Sentry.setUser({ email: 'person@home.com' });
Sentry.addBreadcrumb({ message: 'important message!' });

function longWorkIgnored() {
for (let i = 0; i < 50; i++) {
const salt = crypto.randomBytes(128).toString('base64');
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
assert.ok(hash);
// Busy-block the event loop with pure-JS work. The ANR worker samples the main thread via the
// inspector, which can only pause at a JS safepoint; inside a native call like `crypto.pbkdf2Sync`
// the pause resolves only after the call returns, so the sample can miss `longWork` and land in
// timer internals instead. Pure-JS work keeps `longWork` on the sampled stack for the whole block.
const start = Date.now();
let n = 1;
while (Date.now() - start < 1000) {
n = (n * 1103515245 + 12345) % 2147483648;
}
return n;
}

function longWork() {
for (let i = 0; i < 50; i++) {
const salt = crypto.randomBytes(128).toString('base64');
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
assert.ok(hash);
// Busy-block the event loop with pure-JS work. The ANR worker samples the main thread via the
// inspector, which can only pause at a JS safepoint; inside a native call like `crypto.pbkdf2Sync`
// the pause resolves only after the call returns, so the sample can miss `longWork` and land in
// timer internals instead. Pure-JS work keeps `longWork` on the sampled stack for the whole block.
const start = Date.now();
let n = 1;
while (Date.now() - start < 1000) {
n = (n * 1103515245 + 12345) % 2147483648;
}
return n;
}

setTimeout(() => {
Expand Down
15 changes: 9 additions & 6 deletions dev-packages/node-integration-tests/suites/anr/app-path.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as Sentry from '@sentry/node';
import * as assert from 'assert';
import * as crypto from 'crypto';
import * as path from 'path';
import * as url from 'url';
import { waitForDebuggerReady } from '@sentry-internal/test-utils';
Expand All @@ -23,11 +21,16 @@ Sentry.setUser({ email: 'person@home.com' });
Sentry.addBreadcrumb({ message: 'important message!' });

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);
// Busy-block the event loop with pure-JS work. The ANR worker samples the main thread via the
// inspector, which can only pause at a JS safepoint; inside a native call like `crypto.pbkdf2Sync`
// the pause resolves only after the call returns, so the sample can miss `longWork` and land in
// timer internals instead. Pure-JS work keeps `longWork` on the sampled stack for the whole block.
const start = Date.now();
let n = 1;
while (Date.now() - start < 1000) {
n = (n * 1103515245 + 12345) % 2147483648;
}
return n;
}

waitForDebuggerReady(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as Sentry from '@sentry/node';
import * as assert from 'assert';
import * as crypto from 'crypto';
import { waitForDebuggerReady } from '@sentry-internal/test-utils';

global._sentryDebugIds = { [new Error().stack]: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa' };
Expand All @@ -19,11 +17,16 @@ Sentry.setUser({ email: 'person@home.com' });
Sentry.addBreadcrumb({ message: 'important message!' });

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);
// Busy-block the event loop with pure-JS work. The ANR worker samples the main thread via the
// inspector, which can only pause at a JS safepoint; inside a native call like `crypto.pbkdf2Sync`
// the pause resolves only after the call returns, so the sample can miss `longWork` and land in
// timer internals instead. Pure-JS work keeps `longWork` on the sampled stack for the whole block.
const start = Date.now();
let n = 1;
while (Date.now() - start < 1000) {
n = (n * 1103515245 + 12345) % 2147483648;
}
return n;
}

waitForDebuggerReady(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
const crypto = require('crypto');
const assert = require('assert');

const Sentry = require('@sentry/node');
const { waitForDebuggerReady } = require('@sentry-internal/test-utils');

Expand All @@ -18,11 +15,16 @@ Sentry.setUser({ email: 'person@home.com' });
Sentry.addBreadcrumb({ message: 'important message!' });

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);
// Busy-block the event loop with pure-JS work. The ANR worker samples the main thread via the
// inspector, which can only pause at a JS safepoint; inside a native call like `crypto.pbkdf2Sync`
// the pause resolves only after the call returns, so the sample can miss `longWork` and land in
// timer internals instead. Pure-JS work keeps `longWork` on the sampled stack for the whole block.
const start = Date.now();
let n = 1;
while (Date.now() - start < 1000) {
n = (n * 1103515245 + 12345) % 2147483648;
}
return n;
}

waitForDebuggerReady(() => {
Expand Down
16 changes: 9 additions & 7 deletions dev-packages/node-integration-tests/suites/anr/basic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
const crypto = require('crypto');
const assert = require('assert');

const Sentry = require('@sentry/node');
const { waitForDebuggerReady } = require('@sentry-internal/test-utils');

Expand All @@ -20,11 +17,16 @@ Sentry.setUser({ email: 'person@home.com' });
Sentry.addBreadcrumb({ message: 'important message!' });

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);
// Busy-block the event loop with pure-JS work. The ANR worker samples the main thread via the
// inspector, which can only pause at a JS safepoint; inside a native call like `crypto.pbkdf2Sync`
// the pause resolves only after the call returns, so the sample can miss `longWork` and land in
// timer internals instead. Pure-JS work keeps `longWork` on the sampled stack for the whole block.
const start = Date.now();
let n = 1;
while (Date.now() - start < 1000) {
n = (n * 1103515245 + 12345) % 2147483648;
}
return n;
}

waitForDebuggerReady(() => {
Expand Down
Loading
Loading