Skip to content
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

debugger: prevent simultaneous heap snapshots #39638

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 10 additions & 1 deletion lib/internal/debugger/inspect_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ function createRepl(inspector) {
const history = { control: [], debug: [] };
const watchedExpressions = [];
const knownBreakpoints = [];
let heapSnapshotPromise = null;
let pauseOnExceptionState = 'none';
let lastCommand;

Expand Down Expand Up @@ -961,7 +962,13 @@ function createRepl(inspector) {
},

takeHeapSnapshot(filename = 'node.heapsnapshot') {
return new Promise((resolve, reject) => {
if (heapSnapshotPromise) {
print(
'Cannot take heap snapshot because another snapshot is in progress.'
);
return heapSnapshotPromise;
}
heapSnapshotPromise = new Promise((resolve, reject) => {
gireeshpunathil marked this conversation as resolved.
Show resolved Hide resolved
const absoluteFile = Path.resolve(filename);
const writer = FS.createWriteStream(absoluteFile);
let sizeWritten = 0;
Expand All @@ -983,6 +990,7 @@ function createRepl(inspector) {
writer.end(() => {
teardown();
print(`Wrote snapshot: ${absoluteFile}`);
heapSnapshotPromise = null;
resolve();
});
}
Expand All @@ -1006,6 +1014,7 @@ function createRepl(inspector) {
HeapProfiler.takeHeapSnapshot({ reportProgress: true }),
onResolve, onReject);
});
return heapSnapshotPromise;
},

get watchers() {
Expand Down
48 changes: 0 additions & 48 deletions test/known_issues/test-debugger-takeHeapSnapshot-race.js

This file was deleted.

4 changes: 4 additions & 0 deletions test/sequential/test-debugger-heap-profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const filename = 'node.heapsnapshot';
.then(() => cli.waitForPrompt())
.then(() => cli.command('takeHeapSnapshot()'))
.then(() => JSON.parse(readFileSync(filename, 'utf8')))
// Check that two simultaneous snapshots don't step all over each other.
// Refs: https://github.com/nodejs/node/issues/39555
.then(() => cli.command('takeHeapSnapshot(); takeHeapSnapshot()'))
.then(() => JSON.parse(readFileSync(filename, 'utf8')))
.then(() => cli.quit())
.then(null, onFatal);
}