Intermittent MongoServerSelectionError when connecting from NodeJS using Google Cloud Run + MongoDB Atlas

Hi, i have same issue, with NodeJs and Mongoose, on GCP App Engine with peer conection and using private url:

mongodb+srv://user:pass@xx-pri.qteth.mongodb.net/?retryWrites=true&w=majority

options: {
    useUnifiedTopology: true,
    useNewUrlParser: true,
    useCreateIndex: true,
    useFindAndModify: false,
  }

Node version: 14.17.4
Mongoose verison: 5.13.13

The problem happens intermittently, it does not follow a pattern, it has already happened twice in a day, but it has also been about a month without happening. Here is the error received from the application:

connection timed out MongoServerSelectionError: connection timed out
    at Timeout._onTimeout (/app/node_modules/mongodb/lib/core/sdam/topology.js:438:30)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7)

I tried allow conection from 0.0.0.0/0 but dont work

2 Likes