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

forcing heap snapshot via signal does not allow specifying custom directory #47842

Closed
mateodelnorte opened this issue May 3, 2023 · 6 comments
Labels
good first issue Issues that are suitable for first-time contributors.

Comments

@mateodelnorte
Copy link

Version

18

Platform

mac

Subsystem

No response

What steps will reproduce the bug?

  1. start node process with node --heapsnapshot-signal=SIGUSR2 --diagnostic-dir=/opt/crashes test.js
  2. send signal to snapshot with kill -USR2 [pid]
  3. application will attempt to write the heap shapshot to cwd

Why is this important? --diagnostics-dir is currently being used to write files for heap profiling, but not ad-hoc heap dumps. When running in a production environment, the application cwd is often read only. Application developers must be able to specify where heap dumps will be saved.

Note, no parameters are being passed into this function execution: https://github.com/nodejs/node/blob/c24a61b3f6815b9d12b491ac869335feff86a24b/lib/internal/process/pre_execution.js#LL376C17-L376C17. A path should be passed to this function, such that the full filename can be constructed.

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

Note, no parameters are being passed into this function execution: https://github.com/nodejs/node/blob/c24a61b3f6815b9d12b491ac869335feff86a24b/lib/internal/process/pre_execution.js#LL376C17-L376C17. A path should be passed to this function, such that the full filename can be constructed.

What do you see instead?

writeHeapSnapshot(); attempts to write to the cwd. The code path for writing to a provided path is never utilized.

Additional information

No response

@bnoordhuis bnoordhuis added the good first issue Issues that are suitable for first-time contributors. label May 4, 2023
@bnoordhuis
Copy link
Member

Pull request welcome. The relevant code is here:

function initializeHeapSnapshotSignalHandlers() {
const signal = getOptionValue('--heapsnapshot-signal');
if (!signal)
return;
require('internal/validators').validateSignalName(signal);
const { writeHeapSnapshot } = require('v8');
function doWriteHeapSnapshot() {
writeHeapSnapshot();
}
process.on(signal, doWriteHeapSnapshot);
// The code above would add the listener back during deserialization,
// if applicable.
if (isBuildingSnapshot()) {
addSerializeCallback(() => {
process.removeListener(signal, doWriteHeapSnapshot);
});
}
}

@MrJithil
Copy link
Member

MrJithil commented May 4, 2023

I am on it.

@alexgorunescu97
Copy link

alexgorunescu97 commented May 4, 2023

I was actually in the process of creating a PR. Can I go ahead with it? I saw that it was labeled as a good first issue and I wanted to make a contribution.

@MrJithil
Copy link
Member

MrJithil commented May 4, 2023

Sorry. Next time, you can comment on the issue and take the work. So that, we can avoid the duplicate work.

WhiteMinds added a commit to WhiteMinds/node that referenced this issue Sep 5, 2023
WhiteMinds added a commit to WhiteMinds/node that referenced this issue Sep 5, 2023
WhiteMinds added a commit to WhiteMinds/node that referenced this issue Sep 5, 2023
Trott pushed a commit to MrJithil/node that referenced this issue Sep 5, 2023
PR-URL: nodejs#47854
Refs: nodejs#47842
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
@WhiteMinds
Copy link

It looks like this issue hasn't been responded to in a while, so I created the PR: #49496

@RafaelGSS
Copy link
Member

Completed in #47854

ruyadorno pushed a commit that referenced this issue Sep 28, 2023
PR-URL: #47854
Refs: #47842
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
alexfernandez pushed a commit to alexfernandez/node that referenced this issue Nov 1, 2023
PR-URL: nodejs#47854
Refs: nodejs#47842
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issues that are suitable for first-time contributors.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants