Repository navigation
Node not saving coverage when process is terminated using SIGINT/SIGTERM #35212
Description
Activity
For reference the issue reported by me in c8 repository: bcoe/c8#189
- changed the title
[-]Node not saving coverage when process is terminated using SIGINT and no handler attached[/-][+]Node not saving coverage when process is terminated using SIGINT/SIGTERM[/+]on Sep 15, 2020 - addedduplicateIssues and PRs that are duplicates of other issues or PRs.Issues and PRs that are duplicates of other issues or PRs.
on Sep 16, 2020 @bnoordhuis I don't see how it's a duplicate at all. Here I'm talking about saving coverage data not cpu prof.
If I attach an event listener to node process, coverage is dumped so there is no technical limitation to implement this behavior by default.
A process can receive a signal multiple times and it can delay processing of a signal so there is plenty of time to write the files to the disk.
I guess this isn't really a duplicate - even after we fix the same issue with
--cpu-profwe would still need to add extra code to handle coverage.- addedcoverageIssues and PRs related to Node.js code coverage support.Issues and PRs related to Node.js code coverage support.and removedduplicateIssues and PRs that are duplicates of other issues or PRs.Issues and PRs that are duplicates of other issues or PRs.
on Oct 4, 2020 @bcoe I know you are up to speed on the coverage front.
I believe this used to work ™️. When/if we figure out an approach for
--cpu-prof, let's make sure we apply it to coverage too.Most importantly, let's make sure we add a regression test (could have sworn we had won, funny enough).
I took a look and I think we'd need to just create a different watchdog for the profilers. I'll be refactoring the entire profiler connection class for #33807 and I'll look into how to throw a watchdog into the class
Reacted by Benjamin E. Coe and Andrea ArcuriHi! Could someone explain me (or give me a link) how these signal handlers affect v8 coverage behaviour?
I've read https://v8.dev/blog/javascript-code-coverage, but did not find any signals mention.I.e. I would understand if there was recommendation to call v8.takeCoverage() from SIGTERM handler. But how does this work with only process.exit() in SIGTERM handler ?
@Dzenly Something like
process.on("SIGTERM", v8.stopCoverage)is allowed and should work. The caveats around signal handling are about handling them in C++, not JS. The one JS caveat is thatprocess.on("SIGTERM", ...)won't work when the script is stuck in a busy loop.github-actions commented
on Jun 27, 2026 on Jun 27, 2026 – with GitHub ActionsContributorMore actionsThis 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.- addedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Jun 27, 2026 github-actions commented
on Jul 28, 2026 on Jul 28, 2026 – with GitHub ActionsContributorMore actionsThis 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.
What steps will reproduce the bug?
When running this code
If I stop the process using SIGINT/SIGTERM before the timeout kicks in, coverage is not saved.
What is the expected behavior?
Node coverage should work in the same way as other coverage tools, saving the coverage before terminating the process even if no SIGINT handler is set.
What do you see instead?
No coverage is saved.
Additional information
I know that adding a SIGINT/SIGTERM handler can be used as a workaround but this is not how most applications terminate and has no added value.