Skip to content

Commit

Permalink
Exclude unrefed timers
Browse files Browse the repository at this point in the history
  • Loading branch information
deepal authored and mafintosh committed Mar 6, 2020
1 parent e854ebc commit 010cdb1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions index.js
Expand Up @@ -6,11 +6,11 @@ var sep = path.sep

var active = new Map()
var hook = asyncHooks.createHook({
init (asyncId, type) {
init (asyncId, type, triggerAsyncId, resource) {
if (type === 'TIMERWRAP' || type === 'PROMISE') return
var err = new Error('whatevs')
var stacks = stackback(err)
active.set(asyncId, {type, stacks})
active.set(asyncId, {type, stacks, resource})
},
destroy (asyncId) {
active.delete(asyncId)
Expand All @@ -24,8 +24,13 @@ 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)
var activeResources = [...active.values()].filter(function(r) {
if (r.type === 'Timeout' && !r.resource.hasRef()) return false
return true
})

logger.error('There are %d handle(s) keeping the process running', activeResources.length)
for (const o of activeResources) printStacks(o)

function printStacks (o) {
var stacks = o.stacks.slice(1).filter(function (s) {
Expand Down

0 comments on commit 010cdb1

Please sign in to comment.