my nodejs script is not exiting on its own after successful execution

后端 未结 5 1158
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-14 15:12

I have written a script to update my db table after reading data from db tables and solr. I am using asyn.waterfall module. The problem is that the script is not getting exi

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 15:49

    I just went through this issue.

    The problem with just using process.exit() is that the program I am working on was creating handles, but never destroying them.

    It was processing a directory and putting data into orientdb.

    so some of the things that I have come to learn is that database connections need to be closed before getting rid of the reference. And that process.exit() does not solve all cases.

    When my project processed 2,000 files. It would get down to about 500 left, and the extra handles would have filled up the available working memory. Which means it would not be able to continue. Therefore never reaching the process.exit at the end.

    On the other hand, if you close the items that are requesting the app to stay open, you can solve the problem at its source.

    The two "Undocumented Functions" that I was able to use, were

    process._getActiveHandles();
    process._getActiveRequests();
    

    I am not sure what other functions will help with debugging these types of issues, but these ones were amazing.

    They return an array, and you can determine a lot about what is going on in your process by using these methods.

    I just hope that helps anyone else stumbling across this post.

提交回复
热议问题