Intermittent failed MongoDB connection

Hey Auth0 team, I have been seeing some intermittent connection issues with our database connection to MongoDB. I see some errors like this:

{
  "date": "2024-10-11T17:17:18.819Z",
  "type": "fpurh",
  "description": "MongoNetworkError on post-user-registration: failed to connect to server [redacted.mongodb.net:27017] on first connect [Error: write EPROTO 140168546531200:error:14094438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1544:SSL alert number 80\n\n    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:94:16)\n    at WriteWrap.callbackTrampoline (internal/async_hooks.js:126:14) {\n  name: 'MongoNetworkError',\n  errorLabels: [Array],\n  [Symbol(mongoErrorContextSymbol)]: {}\n}]",
  "connection": "Username-Password-Authentication",
  "user_agent": "Other 0.0.0 / Other 0.0.0",
  "strategy": "auth0",
  "strategy_type": "database",
  "$event_schema": {
    "version": "1.0.0"
  },
  "log_id": "90020241011171718885138000000000000001223372106191051292",
  "tenant_name": "redacted",
}

I redacted some of the log info, but I’m seeing this in my post user registration hook. Similarly, I also see some issues with “Client network socket disconnected before secure TLS connection was established”. It seems there are intermittent connection issues with our MongoDB instance that seem to resolve themselves after some time. We are using mongodb@4.1.0 in our custom DB scripts. Do you have any advice?

Hi @shinkhouse,

Welcome to the Auth0 Community!

It seems that this is an issue from the Mongodb side, and if you’re using Node.js and Mongoose, add the following options in your connection method.

{
  ssl: true,
  tls: true
}

Please check if your IP service provider changes your IP address frequently, specifically the last number. For example, if IP is xxx.xxx.xxx.xxx/32, you can update the IP address in the MongoDB network access settings as: xxx.xxx.xxx.0/0

If you don’t care about security or need to connect from multiple locations (e.g., taking your laptop to different places with different/public Wi-Fi networks), you can use: 0.0.0.0/0

Note: Using 0.0.0.0/0 is not recommended for production environments as it exposes your database to the entire internet. Make sure to use this only if you are aware of the security risks.
Just do this:

  1. Go to your dashboard
  2. Select Network Access in the left menu
  3. Select ADD IP ADDRESS
  4. Put in the Address List Entry this 0.0.0.0 (that means anybody can access your database)
  5. Save and try

Please let me know if this helps and if you have any follow-up questions.

Thanks,
Timotei

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.