Serverless instance MongoSocketReadException: Exception receiving message

Hi guys how are you today?

I am working on a playframework project using scala and mongoDB. We have 3 environments Dev, Demo, Production. The first one runs as a dedicated instance, and the others two are serverless (preview). We are encountering a problem that seems to only happen in Production and Demo and not on Dev (at least we could not reproduce on it).

The error we are getting:

2022-03-23 16:34:03,546[ERROR][services.g.GraphStudyService][scala-execution-context-global-913] - fetchStudiesForPatient: Exception while Getting the encounter for patient 150/ ...25c2d due to com.mongodb.MongoSocketReadException: Exception receiving message
at java.base/
at java.base/
at com.mongodb.internal.connection.tlschannel.impl.TlsChannelImpl.readFromChannel(
at com.mongodb.internal.connection.tlschannel.impl.TlsChannelImpl.readFromChannel(
at com.mongodb.internal.connection.tlschannel.impl.TlsChannelImpl.readAndUnwrap(
at com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup.readHandlingTasks(
at com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup.doRead(
at com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup.lambda$processRead$5(
... 3 common frames omitted

This happens the first time we try to query the mongoDB, then works fine and the same happens when you wait several minutes and try again to get some data from the DB. So we think that maybe the problem is because of the cold start of the severless instance maybe? Or maybe we need to configure something to mantain in some way the connectiona alive.

Please I really need a solution for this since as a said the problems occur in the client’s environment :frowning_face:

Thank you in advance

Hello @Mathias_Medina,

Welcome to the community! :smiley:

Could you please share below details:

  • Does this involve only the server-less instances?
  • Does this happen only with the app, or also with the shell? How about with another driver, e.g. with the Python driver or the node driver?
  • Does this pattern of error, connected, and error again happen consistently and can be reproduced reliably? was any timing pattern noticed? E.g. error, connected for about x minutes, then error again?
  • Which driver and driver version are you using to connect to MongoDB?