gpt4 book ai didi

javascript - Mongoose connectTimeoutMS 回调

转载 作者:行者123 更新时间:2023-11-30 00:25:04 25 4
gpt4 key购买 nike

当出现断线,connectTimeoutMS结束的时候,我想做点什么。我在 Mongoose 配置中使用了这个选项:

var options = {
server: { socketOptions: { keepAlive: 1, connectTimeoutMS: 30000 } }
};

所以 30 秒后它放弃尝试重新连接。有什么好的解决方案可以让我处理这个放弃事件吗?我想在 connectTimeoutMS 结束后做点什么。它应该首先尝试重新连接 30 秒,然后如果失败 - 发出无法重新连接的警告。

最佳答案

你的存活率太低了。来自官方文档-

For long running applications, it is often prudent to enable keepAlive with a number of milliseconds. Without it, after some period of time you may start to see "connection closed" errors for what seems like no reason. If so, after reading this, you may decide to enable keepAlive

关于javascript - Mongoose connectTimeoutMS 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31742374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com