question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Random connection errors in Google Cloud Functions

See original GitHub issue

Do 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:closed
  • Created 2 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
axelvaindalcommented, Nov 17, 2021

Just to double check you have whitelisted your IP?

yes, otherwise the calls would fail all the time not just randomly.

0reactions
vkarpov15commented, Dec 7, 2021

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Random Connection Error in Google Cloud Functions (Python)
Whenever I am getting a connection error inside GCF, Chrome's console logs an error: No 'Access-Control-Allow-Origin' header is present on the ...
Read more >
Troubleshoot External HTTP(S) Load Balancing - Google Cloud
Troubleshoot common issues with Network Analyzer; Backends have incompatible balancing modes; Troubleshoot general connectivity issues.
Read more >
Python Cloud functions throws error intermittently for requests ...
I'm getting random connection errors even when the size of the request is less than 1 kb. The function is being called every...
Read more >
Node 8 - 'connection error' · Issue #429 · firebase ... - GitHub
Hi, after switching our functions to NODE 8 we are seeing "random" function failures with a message connection error.
Read more >
issue with cloudsql closing the connection unexpectedly error
This can happen with different cloud functions (in Python) and it's random. Sometimes I'll go a week without an error and other times...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found