Skip to content

--cpu-prof not generate profile file when killed by SIGINT #27406

Description

@hardfist
  • Version: 12.0.0
  • Platform: mac 10.12.4 && Debian 8
  • Subsystem:
// app.js
// for more info about ReDoS, see:
// https://en.wikipedia.org/wiki/ReDoS

var r = /([a-z]+)+$/
var s = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!'

console.log('Running regular expression... please wait')
for(let i=1;i<100;i++){
  console.time('benchmark');
  const s = 'a'.repeat(i) + '!'
  r.test(s);
  console.timeEnd('benchmark');
}

$ node --cpu-prof app.js 
$ kill -SIGINT {pid}

is this purpose ? or how can i get profile file when app killed by SIGINT?

Activity

  1. added
    questionIssues asking questions about Node.js.
    wontfixIssues that will not be fixed.
    on Apr 25, 2019
  2. bnoordhuis commented on Apr 25, 2019

    @bnoordhuis
    Member

    It's intentional. There is only a very limited number of things you're allowed to do from a signal handler, see signal-safety(7). Creating and writing out a CPU profile isn't one of them.

    edit: this is a partial duplicate of #24937 - specifically, it could be fixed if there was a watchdog thread for handling signals that communicates with the main thread.

  3. added
    duplicateIssues and PRs that are duplicates of other issues or PRs.
    and removed
    wontfixIssues that will not be fixed.
    on Apr 25, 2019
  4. hardfist commented on Apr 25, 2019

    @hardfist
    ContributorAuthor

    It seems that node-report can be generated by SIGUSR2, what makes cpu profile different? @joyeecheung

  5. bnoordhuis commented on Apr 28, 2019

    @bnoordhuis
    Member

    node-report uses a mechanism that integrates with the Node.js event loop, uv_signal_start(). For that to work however the event loop needs to make forward progress, something that won't happen when your script is stuck in a loop.

  6. joyeecheung commented on Apr 29, 2019

    @joyeecheung
    Member

    I think we should be able to fix this based on best-effort - we can just not re-raise the signal directly but instead set something up, return normally, and then outside the handler, terminate the JS execution and do proper cleanups (like what we do for the REPL - which we also need to be careful about), including finishing the CPU profiling.

    We already have a SIGINT watchdog implemented, it's only used in very few places but not globally, though I am not sure if it's adequate for this as we have workers that can profile their own threads but SIGINT is per-process so we may need extra synchronization. I'll take a look.

  7. jasnell commented on Jun 19, 2020

    @jasnell
    Member

    Ping @joyeecheung ... are you still planning to look at this? Should this remain open?

  8. joyeecheung commented on Oct 4, 2020

    @joyeecheung
    Member

    @jasnell Sorry for missing this...yes I think it should remain open, but i don't currently have time to look into it

  9. added
    help wantedIssues that need assistance from volunteers or PRs that need help to proceed.
    and removed
    questionIssues asking questions about Node.js.
    on Oct 4, 2020
  10. joyeecheung commented on Oct 14, 2020

    @joyeecheung
    Member

    I am working on refactoring for #33807 and I think some of the work there might be useful for this. Tentatively assigning this to myself.

  11. removed
    help wantedIssues that need assistance from volunteers or PRs that need help to proceed.
    on Oct 14, 2020
  12. self-assigned this
    on Oct 14, 2020
  13. added
    v8 engineIssues and PRs related to the V8 dependency.
    and removed
    duplicateIssues and PRs that are duplicates of other issues or PRs.
    on Dec 28, 2020
  14. github-actions commented on Jun 27, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 210 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  15. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jun 27, 2026
  16. github-actions commented on Jul 28, 2026

    @github-actions
    Contributor

    This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
    If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.

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

Metadata

Metadata

Assignees

Labels

staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.v8 engineIssues and PRs related to the V8 dependency.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions