MongoDB connection error: MongoNetworkError: when hosted on cyclic

5.3k Views Asked by At

I have a NodeJs API hosted on cyclic. Everything worked fine earlier but I exhausted my free tier API request and my app was suspended, then had to upgrade. Since then I have been having this error

 MongoDB connection error: MongoNetworkError: 805C21D67D7F0000:error:0A000438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:ssl/record/rec_layer_s3.c:1586:SSL alert number 80

    at connectionFailureError (/var/task/node_modules/mongoose/node_modules/mongodb/lib/cmap/connect.js:367:20)
    at TLSSocket.<anonymous> (/var/task/node_modules/mongoose/node_modules/mongodb/lib/cmap/connect.js:290:22)
    at Object.onceWrapper (node:events:629:26)
    at TLSSocket.emit (node:events:514:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  cause: [Error: 805C21D67D7F0000:error:0A000438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:ssl/record/rec_layer_s3.c:1586:SSL alert number 80
  ] {
    library: 'SSL routines',
    reason: 'tlsv1 alert internal error',
    code: 'ERR_SSL_TLSV1_ALERT_INTERNAL_ERROR'
  },
  connectionGeneration: 2,
  [Symbol(errorLabels)]: Set(1) { 'ResetPool' }
}

I have tried everything, I thought my mongo free tier was exhausted. I upgraded that, to no avail. I updated my mongoose package, I have tried searching online but couldn't find any thing. This how I connect to my database in the index.js //Connect to the database before listening

connectDB().then(() => {
  app.listen(PORT, () => {
    console.log(`App listening on port ${PORT}`);
  });
});

And this my connectDB function

const mongoose = require("mongoose");

const connectDB = async () => {
  try {
    await mongoose.connect(process.env.MONGO_URL, {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    });
    console.log("MongoDB connected");
  } catch (error) {
    console.error("MongoDB connection error:", error);
  }
};

module.exports = connectDB;

What exactly could be causing that error and how do I rectify is

1

There are 1 best solutions below

0
Jeff R On

The ERR_SSL_TLSV1_ALERT_INTERNAL_ERROR error (above) can be caused by not whitelisting your IP in Mongo Atlas. Make sure you're not blocked by the Network Access settings! It's a little misleading since it's an "ssl error", but it's actually just telling you that the SSL handshake could not complete (because you're IP is not whitelisted).

So that's at least one possible solution to this error.