Node.JS: Tool to see why process is still running?

后端 未结 1 1613
长情又很酷
长情又很酷 2020-12-05 18:38

Is there a way to see what timeouts, intervals or async operations (or endless loops) are still running and are stopping my process from ending?

I have been able to

相关标签:
1条回答
  • 2020-12-05 19:41

    The module why-is-node-running is exactly the thing you need.

     var log = require('why-is-node-running')
     setTimeout(function () {
       log() // logs out active handles that are keeping node running
     }, 100)
    

    And the output is something like:

    There are 4 known handle(s) keeping the process running and 0 unknown
    Known handles:
    # Timer
    /Users/maf/dev/node_modules/why-is-node-running/example.js:6  - setInterval(function () {}, 1000)
    /Users/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()
    
    # TCP
    /Users/maf/dev/node_modules/why-is-node-running/example.js:7  - server.listen(0)
    /Users/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()
    
    # TCP
    /Users/maf/dev/node_modules/why-is-node-running/example.js:7  - server.listen(0)
    /Users/maf/dev/node_modules/why-is-node-running/example.js:11 - createServer()
    
    # Timer
    /Users/maf/dev/node_modules/why-is-node-running/example.js:13 - setTimeout(function () {
    
    0 讨论(0)
提交回复
热议问题