Random connection errors in Google Cloud Functions
See original GitHub issueDo you want to request a feature or report a bug?
BUG
What is the current behavior?
We are using Mongoose inside our Google Cloud Functions and we have a lot of errors related to the connection that seems very unstable. We have a lot of traffic in our cloud functions, something like dozens of calls per second.
Most of the time the functions run well, but a non-neglectable percentage of our traffic is broken due to a connection error I’m unable to troubleshoot.
I’ve tried reproducing with a simple cloud function that connects to Mongoose and runs every minute, and I’ve had 3 times the MongooseServerSelection
error in two days.
We also have random massive spike of MongoNetworkError: Client network socket disconnected before secure TLS connection was established
I cannot explain.
If the current behavior is a bug, please provide the steps to reproduce.
This script is the reproduction I used to have the 3 random MongooseServerSelectionError
import type { Connection, Model } from "mongoose";
import mongoose from "mongoose";
import * as functions from "firebase-functions";
const { db } = functions.config();
let connection: Connection = null;
let model: Model<any> | null;
export default async function testMongoose() {
if (!connection) {
connection = await mongoose.createConnection(db.url);
await connection
.asPromise()
.catch((error) => logger.error("A db error has occured.", { error })); // This here is never executed in the logs.
model = connection.model(
"test_data",
new mongoose.Schema({ message: String })
);
}
await model.create({ message: "This is a test data." });
}
What is the expected behavior?
We no longer have unknown network errors.
What are the versions of Node.js, Mongoose, and MongoDB you are using? Note that “latest” is not a version. Node 14.X MongoDB v4.2 Mongoose v6.0.12
Issue Analytics
- State:
- Created 2 years ago
- Comments:10
yes, otherwise the calls would fail all the time not just randomly.
@axelvaindal can you try reducing
maxPoolSize
to 5? That may help.it’s not really possible for us to say how many connections should be opened for a given number of function invocations without studying your code and access patterns.