Mongoose: “首次连接时连接失败”后不再重试

创建于 2017-04-17  ·  40评论  ·  资料来源: Automattic/mongoose

默认情况下,如果第一次连接失败,mongoose 会抛出错误,从而导致节点崩溃。

因此,要重现此错误,您需要在应用程序中使用以下代码来捕获错误并防止崩溃:

db.on('error', console.error.bind(console, 'connection error:'));

现在我们可以按如下方式重现这个错误:

  1. 关闭你的 MongoDB
  2. 启动使用 mongoose 的节点应用程序
  3. 您的应用将记录: [MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]]
  4. 再次启动你的 MongoDB
  5. 观察 mongoose 现在没有连接到正在运行的 MongoDB。 重新连接的唯一方法是重新启动您的应用程序,或使用手动解决方法

预期行为:由于autoreconnect默认为 true,我希望 mongoose 在 MongoDB 再次可访问后不久建立连接。

注意:如果第一次连接成功,但与 MongoDB 的连接在运行时丢失,则自动重新连接正常工作,如预期。 如果应用程序启动时 MongoDB 不可用,则问题是不一致。

(如果这是所需的行为,并且建议开发人员通过不捕获错误并让节点崩溃来处理这种情况,那么我可以接受这一点,但值得澄清。)

节点v4.4.1, [email protected][email protected][email protected]

最有用的评论

对于任何想要在第一次连接失败时自动重新连接的人,我是这样处理的:

function createConnection (dbURL, options) {
    var db = mongoose.createConnection(dbURL, options);

    db.on('error', function (err) {
        // If first connect fails because mongod is down, try again later.
        // This is only needed for first connect, not for runtime reconnects.
        // See: https://github.com/Automattic/mongoose/issues/5169
        if (err.message && err.message.match(/failed to connect to server .* on first connect/)) {
            console.log(new Date(), String(err));

            // Wait for a bit, then try to connect again
            setTimeout(function () {
                console.log("Retrying first connect...");
                db.openUri(dbURL).catch(() => {});
                // Why the empty catch?
                // Well, errors thrown by db.open() will also be passed to .on('error'),
                // so we can handle them there, no need to log anything in the catch here.
                // But we still need this empty catch to avoid unhandled rejections.
            }, 20 * 1000);
        } else {
            // Some other error occurred.  Log it.
            console.error(new Date(), String(err));
        }
    });

    db.once('open', function () {
        console.log("Connection to db established.");
    });

    return db;
}

// Use it like
var db = createConnection('mongodb://...', options);
var User = db.model('User', userSchema);

对于 mongoose < 4.11 使用db.open()而不是db.openUri()
对于猫鼬 4.11.7,此技术不起作用。
对于猫鼬 4.13.4,它又开始工作了!


编辑 2019/09/02:还有一个更短的解决方案,使用promiseRetry here

所有40条评论

可以确认。
节点 6、7、猫鼬(至少 6 个月)、mongo 3.2 - 3.4
和这个一起来#4890

我猜这是一个mongodb-core问题。 即使我认为第一次尝试失败,它也应该尝试重新连接,因为我不确定为什么这与后续尝试不同。

你也可以在那里报告这个问题吗?

这是一个完整的重现脚本:

const mongoose = require('mongoose');
const co = require('co');
mongoose.Promise = global.Promise;
const GITHUB_ISSUE = `gh-5169`;


exec()
  .catch(error => {
    console.error(`Error: ${ error }\n${ error.stack }`);
  });


function exec() {
  return co(function*() {
    const db = mongoose.createConnection(`mongodb://localhost:27017/${ GITHUB_ISSUE }`);
    db.on('error', (error) => {
      console.error(`in an error ${ error }\n${ error.stack }`);
    })
  });
}

感谢您的重现。 我已经研究过mongodb-core。 这是驱动程序

如果无法连接到主机,驱动程序将在第一次连接时失败。 这是为了确保无法访问的主机上的快速故障而设计的。 重新连接行为仅在驱动程序执行初始连接后才会启动。

由应用程序决定要做什么。 这是为了确保驱动程序快速失败并且不会让您认为它实际上在工作,这是设计使然。

所以我怀疑我们不会从司机那里得到任何不同的行为。

我实际上认为这种行为对于低级驱动程序是合理的。 它将帮助那些不小心尝试连接到错误主机或错误端口的开发人员。

但是如果我们想在 mongoose 中做一些对开发人员更友好的事情,我们可以考虑:

  • 启用自动重新连接选项后,继续尝试重新连接,直到可以联系到 Mongo 服务器(通过构建类似上面链接的解决方法)。
  • mongoose 这样做的时候记录一下,所以在连接永远不会建立的情况下,开发者至少会知道问题出在哪里。
    (日志可以推迟,例如 30 秒。实际上,不是直接记录,我想我们应该发出一个咨询error事件,但仍然尝试自动重新连接。)

如果我没记错的话,当我使用该解决方法并在几次失败尝试后最终连接时,应用程序已排队的查询确实按需要执行。 (但这值得再次测试。)

我认为这实际上是一个不错的主意,我会将其标记为功能请求

不,在初始连接上快速失败是跨 MongoDB 驱动程序的一种非常一致的行为,猫鼬支持它并没有太大好处。

最近来自 Strongloop Loopback mongodb 连接器的lazyConnect标志将第一个连接推迟到端点被命中。 如果在这种情况下第一次连接失败,则默认连接丢失设置将生效(它将重试)。

我的兴趣是容器编排,其中“容器启动顺序”通常可以设置和预期,但“服务可用性顺序”不能。 即使 mongo 服务尚不可用,编排工具也可能会确认 mongo 容器已“启动”。

因此,如果我的 mongo 容器需要 1 秒启动但服务可用 5 秒,而我的应用容器需要 1 秒启动和服务可用 1 秒,应用服务将超过 mongo 服务,导致第一次连接失败如最初所述

Docker Compose 文档是这样说的:

Compose 不会等到容器“准备好”(无论这对您的特定应用程序意味着什么) - 只会等到它运行。 这是有充分理由的。

等待数据库(例如)准备就绪的问题实际上只是分布式系统更大问题的一个子集。 在生产中,您的数据库可能随时不可用或移动主机。 您的应用程序需要对这些类型的故障具有弹性。

要处理此问题,您的应用程序应尝试在失败后重新建立与数据库的连接。 如果应用程序重试连接,它最终应该能够连接到数据库。

最好的解决方案是在您的应用程序代码中执行此检查,无论是在启动时还是在由于任何原因丢失连接时

因此,在容器编排的上下文中存在明显的差距,但这两种立场似乎都是有效的:

  1. Mongoose 可以支持在第一次连接时重试的选项(可能在某些警告文档中默认为 false),或者
  2. Mongoose 可以让开发人员负责编写代码以在第一次连接失败时重试。

当然,存在差距,但是如果初始连接失败,则由您负责决定是否重试。 所有猫鼬告诉你的是它失败了。 如果您做出在生产中(或在任何上下文中)使用 docker compose 的可疑决定,则由您来处理重试初始连接失败。

立场2,那么。

对于任何想要在第一次连接失败时自动重新连接的人,我是这样处理的:

function createConnection (dbURL, options) {
    var db = mongoose.createConnection(dbURL, options);

    db.on('error', function (err) {
        // If first connect fails because mongod is down, try again later.
        // This is only needed for first connect, not for runtime reconnects.
        // See: https://github.com/Automattic/mongoose/issues/5169
        if (err.message && err.message.match(/failed to connect to server .* on first connect/)) {
            console.log(new Date(), String(err));

            // Wait for a bit, then try to connect again
            setTimeout(function () {
                console.log("Retrying first connect...");
                db.openUri(dbURL).catch(() => {});
                // Why the empty catch?
                // Well, errors thrown by db.open() will also be passed to .on('error'),
                // so we can handle them there, no need to log anything in the catch here.
                // But we still need this empty catch to avoid unhandled rejections.
            }, 20 * 1000);
        } else {
            // Some other error occurred.  Log it.
            console.error(new Date(), String(err));
        }
    });

    db.once('open', function () {
        console.log("Connection to db established.");
    });

    return db;
}

// Use it like
var db = createConnection('mongodb://...', options);
var User = db.model('User', userSchema);

对于 mongoose < 4.11 使用db.open()而不是db.openUri()
对于猫鼬 4.11.7,此技术不起作用。
对于猫鼬 4.13.4,它又开始工作了!


编辑 2019/09/02:还有一个更短的解决方案,使用promiseRetry here

@vkarpov15 ,发生这种情况时还会记录来自 mongodb-core 库的未处理拒绝。

MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
    at Pool.<anonymous> (/Users/development/okkralabs/sem-server/services/sem-access/node_modules/mongodb-core/lib/topologies/server.js:336:35)
    at emitOne (events.js:116:13)
    at Pool.emit (events.js:211:7)
    at Connection.<anonymous> (/Users/development/okkralabs/sem-server/services/sem-access/node_modules/mongodb-core/lib/connection/pool.js:280:12)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at Connection.emit (events.js:214:7)
    at Socket.<anonymous> (/Users/development/okkralabs/sem-server/services/sem-access/node_modules/mongodb-core/lib/connection/connection.js:187:49)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

这很容易重现,尝试连接不可用的 MongoDb 服务器。

(node:2545) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
(node:2545) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

有什么办法处理吗?

@jorgearanda你使用的是什么版本的猫鼬,你能提供一些代码示例吗?

@vkarpov15我认为这是给@jorgecuesta的信息?

糟糕,我的错。 愚蠢的 github 自动完成,是的,那是给@jorgecuesta 的

我看到的内容与@jorgecuesta 完全相同,我使用的是 4.11.5,但在 5.0.0-rc2 中看到的内容相同。 我正在使用 createConnection,因为某些模型在同一个 mongo 实例上使用不同的数据库。 在 mongo 关闭时启动服务器时会发生这种情况:

2018-01-07 13:05:23-05:00: [INFO] database - reusing existing connectioun for mongodb://localhost/eiss
2018-01-07 13:05:23-05:00: [INFO] database - initializing database connection to: mongodb://localhost/eiss
2018-01-07 13:05:23-05:00: [INFO] database - reusing existing connectioun for mongodb://localhost/eiss
2018-01-07 13:05:23-05:00: [ERROR] database - Mongoose connection error: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
Unhandled rejection MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
    at Pool.<anonymous> (/Users/bill/eiss4/js/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/server.js:503:11)
    at emitOne (events.js:116:13)
    at Pool.emit (events.js:211:7)
    at Connection.<anonymous> (/Users/bill/eiss4/js/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:326:12)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at Connection.emit (events.js:214:7)
    at Socket.<anonymous> (/Users/bill/eiss4/js/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:245:50)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

模型使用它们正在使用的数据库的名称调用连接函数(如下)。 只要服务器启动时 mongo 正在运行,启动和关闭数据库就可以重新连接(记录错误)。 我刚刚在阅读这个问题时意识到驱动程序以不同的方式处理初始连接,这有点烦人。 我将尝试@joeytwiddle的解决方法,但我怀疑这个未处理的异常仍然会发生?

const allConnections = {};

module.exports = function(dbName) {
  const url = 'http://localhost/' + dbName;
  let conn;
  log.info('initializing database connection to: ' + url);

  conn = allConnections[url];
  if (!conn) {
    log.info('creating new connection for ' + url);
    conn = mongoose.createConnection(url, {
      useMongoClient: true,
      autoReconnect: true,
      autoIndex: false,
      reconnectTries: Number.MAX_SAFE_INTEGER
    });    
    // Log database connection events
    conn.on('connected', () => log.info('Mongoose connection open to ' + url));
    conn.on('error', (err) =>  log.error('Mongoose connection error: ' + err));
    conn.on('disconnected', () => log.error('Mongoose connection disconnected'));  
    allConnections[url] = conn;
  }
  else {
    log.info('reusing existing connection for ' + url);
  }
  return conn;
}

@raythree在上述情况下你应该没问题,因为你有.on('error') 。 如果您想在失败时重试初始连接,我建议您只使用 async/await

let conn;
for (let i = 0; i < numRetries; ++i) {
  try {
    conn = await mongoose.createConnection(uri);
    break;
  } catch (error) {}
}

@vkarpov15很抱歉延迟回复您,我们正在使用 4.11.14 和 4.13.4

@jorgecuestamongoose.connect(uri).catch(err => {})

@vkarpov15 connect() 返回连接实例对吗?

const connection = mongoose.connect(uri || undefined, {useMongoClient: true});
connection.once('error', (e) => {
  console.error(e, 'mongoose connection error.');
});
connection.once('connected', () => {
  console.log('mongoose connected');
});

在 5.0.0 中,我们对其进行了更改,因此mongoose.connect()始终返回一个 promise。 在 4.x 中,它返回一个连接实例,但带有.then().catch()因此您可以将它与await

嗨@joeytwiddle。

我在部署到 Heroku 时遇到了同样的问题。
MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]

在 2017 年 7 月 12 日的评论中,您提供了解决方法/解决方案。 我是 Mongoose/Node 的新手。 你能告诉我你的 createConnection 函数应该放在哪个文件中吗?

我正在运行猫鼬:^5.0.10,节点:v9.4.0
干杯

@juancarlucci你可以把它放在你喜欢的任何文件中。 只需调用它即可获取 mongoose 实例并使用它来创建您的模型。

我已经更新了之前的评论以显示使用示例。

@joeytwiddle感谢您的使用示例! 干杯。

当我尝试连接到 mongo 时,它会引发错误:

connection error: { MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connection 0 to localhost:27017 timed out]
    at Pool.<anonymous> (/home/wasd_xyz/Desktop/test/node_modules/mongodb-core/lib/topologies/server.js:505:11)
    at emitOne (events.js:116:13)
    at Pool.emit (events.js:211:7)
    at Connection.<anonymous> (/home/wasd_xyz/Desktop/test/node_modules/mongodb-core/lib/connection/pool.js:329:12)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at Connection.emit (events.js:214:7)
    at Socket.<anonymous> (/home/wasd_xyz/Desktop/test/node_modules/mongodb-core/lib/connection/connection.js:256:10)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:106:13)
    at Socket.emit (events.js:208:7)
    at Socket._onTimeout (net.js:420:8)
    at ontimeout (timers.js:482:11)
    at tryOnTimeout (timers.js:317:5)
    at Timer.listOnTimeout (timers.js:277:5)
  name: 'MongoNetworkError',
  message: 'failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connection 0 to localhost:27017 timed out]' }
(node:5453) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connection 0 to localhost:27017 timed out]
    at Pool.<anonymous> (/home/wasd_xyz/Desktop/test/node_modules/mongodb-core/lib/topologies/server.js:505:11)
    at emitOne (events.js:116:13)
    at Pool.emit (events.js:211:7)
    at Connection.<anonymous> (/home/wasd_xyz/Desktop/test/node_modules/mongodb-core/lib/connection/pool.js:329:12)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at Connection.emit (events.js:214:7)
    at Socket.<anonymous> (/home/wasd_xyz/Desktop/test/node_modules/mongodb-core/lib/connection/connection.js:256:10)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:106:13)
    at Socket.emit (events.js:208:7)
    at Socket._onTimeout (net.js:420:8)
    at ontimeout (timers.js:482:11)
    at tryOnTimeout (timers.js:317:5)
    at Timer.listOnTimeout (timers.js:277:5)
(node:5453) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:5453) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


须藤服务 mongodb 状态

● mongodb.service - MongoDB Database
   Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: 
   Active: active (running) since Sat 2018-06-23 17:13:28 IST; 13min ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 4224 (mongod)
    Tasks: 24 (limit: 4915)
   CGroup: /system.slice/mongodb.service
           └─4224 /usr/bin/mongod --quiet --config /etc/mongod.conf

Jun 23 17:13:28 Inspiron5370 systemd[1]: Started MongoDB Database.


@pranshuchittora你能展示你的 MongoDB 配置文件吗? 确保端口是 27017。另外,尝试使用 127.0.0.1 而不是 localhost

尝试使用 ip 而不是 localhost 连接来解决您的问题。

 let local = "mongodb://127.0.0.1:27017/XXX";
      mongoose.connect(
        local,
        { useNewUrlParser: true }
      );

如果第一次尝试连接失败,它总是会抛出错误。
您可以使用下面的方法绕过它(例如,在您的应用程序/脚本启动之前要确保数据库正在运行时):

猫鼬@5.3.16
@types/猫鼬@
@types/ [email protected]

async function waitForMongoDBStart(uri: string, timeoutMs: number) {

    return new Promise( async (resolve, reject) => {

        let endTime = Date.now() + timeoutMs;


        while (true) {

            let connectionError: Error;

            function errorHandler(err: Error) {
                connectionError = err;
            }
            mongoose.connection.once("error", errorHandler);

            await mongoose.connect(uri, {
                connectTimeoutMS: 5000, // This timeout applies only after connected & connection lost
                useNewUrlParser: true,
                useFindAndModify: false
            });

            // Time for error event propagation
            await wait(0);

            if ( ! connectionError) {
                mongoose.connection.removeListener("error", errorHandler);
                return resolve(); // All OK, connected
            }

            if (connectionError.name !== "MongoNetworkError") {
                return reject(`Unable to connect mongoDB. Details: ${connectionError}`);
            }

            if (Date.now() > endTime) {
                return reject(`Unable to connect mongoBD in ${timeoutMs} ms. Details: ${connectionError}`);
            }

        }

    });
}

@vkarpov15这是非常不明显的行为。 从https://mongoosejs.com/docs/connections.html

connectTimeoutMS - How long the MongoDB driver will wait 
before failing its initial connection attempt. 
Once Mongoose has successfully connected, connectTimeoutMS is no longer relevant.

文档说它应该与初始连接一起工作,但事实并非如此。 由于failed to connect to server错误,它立即失败。

如果它在 MongoDB 驱动程序中具有一致的行为,那么最好有一些像reconnectOnInitialFail这样的选项,默认情况下它是false

当前行为与 vkarpov15 描述的行为相反 -
connectImeoutMS 仅在第一次连接后才重要(在第一次连接时
预计 DB 已启动并接受连接,否则立即
抛出错误)

呜咽,22 gru 2018 o 13:03 Dmitry Kirilyuk [email protected]
napisał(a):

如果跨 MongoDB 驱动程序的行为一致,那么最好
有一些像 reconnectOnInitialFail 这样的选项,这将是错误的
默认


您收到此消息是因为您发表了评论。
直接回复本邮件,在GitHub上查看
https://github.com/Automattic/mongoose/issues/5169#issuecomment-449565468
或静音线程
https://github.com/notifications/unsubscribe-auth/ABY-TjgeI2UqVca050y5YY3zi6w7nMkfks5u7h-vgaJpZM4M-1ur
.

——
沃伊切赫·费德雷克

手机:+48 516 661 428

如果我没记错的话,connectTimeoutMS 对初始连接很重要,具体取决于网络条件和操作系统。 初始连接后 connectTimeoutMS 什么时候重要?

在我的情况下,当我第一次尝试连接到Windows 10Alpine Linux (版本未知)上的localhost mongod 实例时,立即抛出错误。 Mongod 实例尚未启动。
除了本地主机之外的其他示例? 任何人?

@fider @Jokero我进一步深入研究,我是对的, connectTimeoutMS仅在您建立初始连接之前才重要,之后socketTimeoutMS接管。 这是 MongoDB 驱动程序中的相关代码:

connectTimeoutMS并不总是有用,因为您通常会收到 DNS 错误或连接被拒绝的错误。 但是,如果你打开一个 TCP 服务器,它监听一个端口但实际上什么都不做:

const net = require('net');

const server = net.createServer();

server.listen(27055);

你会看到connectTimeoutMS开始了:

const assert = require('assert');
const mongoose = require('mongoose');
mongoose.set('debug', true);

const { Schema } = mongoose;

run().then(() => console.log('done')).catch(error => console.error(error.stack));

async function run() {
  await mongoose.connect('mongodb://localhost:27055', {
    useNewUrlParser: true,
    connectTimeoutMS: 1000,
    socketTimeoutMS: 25000
  });
} 
$ time node gh-5169.js 
MongoNetworkError: connection 0 to localhost:27055 timed out
    at Socket.<anonymous> (/mongoose/node_modules/mongodb-core/lib/connection/connection.js:259:7)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:106:13)
    at Socket.emit (events.js:208:7)
    at Socket._onTimeout (net.js:407:8)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)

real    0m2.293s
user    0m0.271s
sys 0m0.043s
$ 

有时由于网络限制,MongoDB url 被阻止,请尝试更改您的网络/互联网源。

https://stackoverflow.com/questions/47958683/cannot-connect-to-mongodb-atlas-through-mongo-shell?answertab=active#tab -top

进行初始连接时,(至少)可能发生三件事:

  1. 有一个mongodb,连接成功,耶!

  2. 服务器响应“连接被拒绝”,这意味着没有进程侦听此端口,或者有防火墙_主动拒绝_连接。 (这通常会立即发生,我认为这就是 fider 所经历的。)

  3. 服务器根本不响应,例如防火墙_被动丢弃_数据包或该 IP 地址上没有服务器。 (在这种情况下,最终会触发 vkarpov 的connectTimeoutMS 。)

所以超时并不总是使用。 只有在给定时间内没有明确的成功或失败时才使用它。

这在网络中很常见,在与不合作的人交谈时也很常见。 您的请求可能会遭到两种类型的拒绝:“不!” 和 .....

感谢@joeytwiddle的可靠解释:+1:

应该如何通过使用mongodb+srv副本集连接来处理这种行为? 当我的副本集处于滚动重启场景(数据库更新)时,我开始收到类似connect ECONNREFUSED 34.238.xxx.xxx:27017

@esetnik你在使用useUnifiedTopology: true和 Mongoose 5.7.5 吗? 我们发现了一个可能相关的问题 #8209。

@vkarpov15是的,我是! 谢谢你的提示。 我将在禁用统一拓扑后运行一些测试并报告我的发现。

你好。 我的项目中有完全相同的问题。 你有没有找到解决办法?!

@fdmxfarhan请打开一个单独的问题并遵循问题模板。

此页面是否有帮助?
0 / 5 - 0 等级