我编写了一个脚本来在从 db 表和 solr 读取数据后更新我的 db 表.我正在使用 asyn.waterfall 模块.问题是在成功完成所有操作后脚本没有退出.我使用过 db 连接池也认为可能正在创建脚本以无限等待.我想将此脚本放在 crontab 中,如果它不能正确退出,则会不必要地创建大量实例.
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 exited after successful completion of all operations. I have used db connection pool also thinking that may be creating the script to wait infinitly. I want to put this script in crontab and if it will not exit properly it would be creating a hell lot of instances unnecessarily.
我刚刚解决了这个问题.
I just went through this issue.
仅使用 process.exit()
的问题在于我正在处理的程序正在创建句柄,但从未销毁它们.
The problem with just using process.exit()
is that the program I am working on was creating handles, but never destroying them.
它正在处理一个目录并将数据放入orientdb.
It was processing a directory and putting data into orientdb.
所以我学到的一些东西是在摆脱引用之前需要关闭数据库连接.而 process.exit()
并不能解决所有情况.
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.
当我的项目处理 2,000 个文件时.它会减少到大约 500 个,额外的句柄会填满可用的工作内存.这意味着它将无法继续.因此永远不会到达 process.exit
最后.
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.
这篇关于成功执行后,我的 nodejs 脚本没有自行退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!