Node.js: inspect what's left in the event loop that's preventing the script from exiting naturally

匿名 (未验证) 提交于 2019-12-03 02:46:02

问题:

Node.js script won't exit if there's callbacks left in the main event loop. While one could forcefully terminate the script by calling process.exit() or throwing exceptions, it is recommended to let the script terminate "naturally", by always doing proper cleanup. However, this sometimes can be difficult as bugs in the code may prevent proper cleanup, e.g., I may forget to remove an IntervalObject when no longer needed, etc., which eventually prevents the program from terminating.

Therefore, is there a way to debug a non-terminating script to find out what's remaining registered in the event loop? In other words, is there a way in Node.js to debug what's preventing the program from exiting?

回答1:

You can call process._getActiveRequests() to get a list of active I/O requests and process._getActiveHandles() to get a list of open handles/file descriptors.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!