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/sun.nio.ch.IOUtil.read(IOUtil.java:223)
at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:356)
at com.mongodb.internal.connection.tlschannel.impl.TlsChannelImpl.readFromChannel(TlsChannelImpl.java:357)
at com.mongodb.internal.connection.tlschannel.impl.TlsChannelImpl.readFromChannel(TlsChannelImpl.java:344)
at com.mongodb.internal.connection.tlschannel.impl.TlsChannelImpl.readAndUnwrap(TlsChannelImpl.java:629)
at com.mongodb.internal.connection.tlschannel.impl.TlsChannelImpl.read(TlsChannelImpl.java:236)
at com.mongodb.internal.connection.tlschannel.ClientTlsChannel.read(ClientTlsChannel.java:168)
at com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup.readHandlingTasks(AsynchronousTlsChannelGroup.java:601)
at com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup.doRead(AsynchronousTlsChannelGroup.java:566)
at com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup.lambda$processRead$5(AsynchronousTlsChannelGroup.java:478)
... 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?

Regards,
Tarun

2 Likes