Skip to content

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

Description

@mateodelnorte

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

Activity

  1. bnoordhuis commented on May 4, 2023

    @bnoordhuis
    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);
    });
    }
    }

  2. MrJithil commented on May 4, 2023

    @MrJithil
    Member

    I am on it.

  3. alexgorunescu97 commented on May 4, 2023

    @alexgorunescu97

    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.

  4. MrJithil commented on May 4, 2023

    @MrJithil
    Member

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

  5. WhiteMinds commented on Sep 6, 2023

    @WhiteMinds

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

  6. RafaelGSS commented on Sep 16, 2023

    @RafaelGSS
    Member

    Completed in #47854

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIssues that are suitable for first-time contributors.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions