Skip to content

Logging multiple times over the course of a programs lifetime #42

@badeball

Description

@badeball

With v2.0.3, invoking the exported log disables the hook. I needed a more complete picture of what was going on during closing of an application because the answer to "why is node running" kept changing. Hence, I tried to sample open handlers as shown below.

for (let i = 0; i < 10; i++) {
  setTimeout(log, (i + 1) * 500);
}

However, this was obviously not possible. It worked with the following patch, in case anyone also needs this, and I am lightly suggesting it as an addition.

--- index.js
+++ index.js
@@ -23,9 +23,8 @@
 function whyIsNodeRunning (logger) {
   if (!logger) logger = console
 
-  hook.disable()
   logger.error('There are %d handle(s) keeping the process running', active.size)
-  for (const o of active.values()) printStacks(o)
+  for (const o of [...active.values()]) printStacks(o)
 
   function printStacks (o) {
     var stacks = o.stacks.slice(1).filter(function (s) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions