MongoDB Atlas Serverless Timeout

I migrate to Serverless and I wish I hadn’t done that. My ASP.NET Core 8 apps hosted on azure app services keeps throwing “Unable to read data from the transport connection: Connection timed out.” exception, we’re using the latest mongodb driver everything was working well before we migrated to Serverless. How can we solve this problem?

Hi there

I recommend that you chat with support to help debug the issue. You can click on “Chat now” on this page to start your chat. Please feel free to DM me if you have any further questions.


Update: It turned out that we were aggressively creating many MongoClient objects in a core function. We fixed the bug by injecting a singleton MongoClient object. Sorry for bothering @Anurag_Kadasne

P.S> We didn’t notice any timeout errors when were using the Shared plan


Hi @Anurag_Kadasne,

Unfortunately the problem re-appeared today, we’ve done an intensive tests to make sure we only consume one MongoClient object in our code base. I hope if you can recommend something we can do or try.


@Anurag_Kadasne @SFM_K_4 I have similar setup and facing the same issue. I am using singletone MongoClient. Did you find any solutions?

Can I get the

  1. Timestamps of the error
  2. Error messages
  3. What driver you are using, along with the version number

Hi @Anurag_Kadasne

Here are the timestamps

  • 5/3/2024, 5:46:32.772 AM
  • 5/2/2024, 11:18:55.401 AM
  • 5/2/2024, 11:19:23.683 AM
  • 5/2/2024, 11:20:04.616 AM

Error messages is
Unable to read data from the transport connection: Connection timed out.

The error is intermittent but it keeps happening every now and then

I am using the C# MongoDB Driver

Hi @Hossam_Barakat

Unfortunately, nothing worked for me, I spent days trying to figure it out, and I ended up doing the following: -
1- I created a ping endpoint
2- I used Azure logic app to send requests to the ping endpoint every 5 minutes
app.MapGet(“/ping”, async (IDBSettings database) =>
await database.Connection.ListDatabaseNamesAsync();
return “refreshed”;

this way the connection to the database will be refreshed and the timeout problem won’t appear

Thanks for the update, I ended up moving to dedicated instance…it is very frustrating issue.