title: Mongodb java driver- java.net.SocketException: Connection reset
body: <p>We have a replication setup with a primary, secondary and arbiter node running mongodb community server v3.4.16.</p>
  
  <p>We are using jasperserver to generate 100+ reports from mongodb database.</p>
  
  <p>Recently we have started facing connection reset problems while connecting to mongodb server due to which reports are failing randomly.</p>
  
  <p>The application (jasperserver) and mongodb are in same network and there' no firewall in between them.</p>
  
  <p>Can someone provide any directions to further investigate the root cause so that it can be fixed?</p>
  
  <p>2018-12-07 03:46:00,631 ERROR MongoDbConnectionFactory,quartzScheduler_Worker-34:85 - Cannot validate object; Caused by: Cannot test MongoDB connection; Caused by: Exception receiving message2018-12-07 03:46:00,631 ERROR MongoDbConnectionFactory,quartzScheduler_Worker-34:85 - Cannot validate object; Caused by: Cannot test MongoDB connection; Caused by: Exception receiving messagenet.sf.jasperreports.engine.JRException: Cannot test MongoDB connection; Caused by: Exception receiving message at com.jaspersoft.mongodb.connection.MongoDbConnection.test(MongoDbConnection.java:193) at com.jaspersoft.mongodb.connection.MongoDbConnectionFactory.validateObject(MongoDbConnectionFactory.java:83) at com.jaspersoft.mongodb.connection.MongoDbConnectionFactory.validateObject(MongoDbConnectionFactory.java:29) at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1165) at com.jaspersoft.mongodb.connection.MongoDbConnectionManager.borrowConnection(MongoDbConnectionManager.java:66) at com.jaspersoft.mongodb.jasperserver.MongoDbDataSourceService45.createConnection(MongoDbDataSourceService45.java:90) at com.jaspersoft.mongodb.jasperserver.MongoDbDataSourceService45.setReportParameterValues(MongoDbDataSourceService45.java:75) at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.fillReport(EngineServiceImpl.java:1806) at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl$ReportFill.runWithDataSource(EngineServiceImpl.java:1143) at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl$ReportFill.runReport(EngineServiceImpl.java:1072) at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl$ReportRunnable.run(EngineServiceImpl.java:967) at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl$SynchronousExecutor.execute(EngineServiceImpl.java:945) at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.fillReport(EngineServiceImpl.java:651) at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.executeReportUnitRequest(EngineServiceImpl.java:2068) at com.jaspersoft.jasperserver.api.engine.jasperreports.domain.impl.ReportUnitRequest.execute(ReportUnitRequest.java:67) at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.execute(EngineServiceImpl.java:529) at com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportExecutionJob.runReport(ReportExecutionJob.java:836) at com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportExecutionJob.executeReport(ReportExecutionJob.java:803) at com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportExecutionJob.executeReport(ReportExecutionJob.java:704) at com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportExecutionJob.executeAndSendReport(ReportExecutionJob.java:499) at com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportExecutionJob.execute(ReportExecutionJob.java:248) at org.quartz.core.JobRunShell.run(JobRunShell.java:213) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)Caused by: com.mongodb.MongoSocketReadException: Exception receiving message at com.mongodb.connection.InternalStreamConnection.translateReadException(InternalStreamConnection.java:480) at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:225) at com.mongodb.connection.UsageTrackingInternalConnection.receiveMessage(UsageTrackingInternalConnection.java:102) at com.mongodb.connection.DefaultConnectionPool$PooledConnection.receiveMessage(DefaultConnectionPool.java:435) at com.mongodb.connection.CommandProtocol.execute(CommandProtocol.java:112) at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:159) at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:286) at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:173) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:215) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:186) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:178) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:91) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:84) at com.mongodb.operation.CommandReadOperation.execute(CommandReadOperation.java:55) at com.mongodb.Mongo.execute(Mongo.java:772) at com.mongodb.Mongo$2.execute(Mongo.java:759) at com.mongodb.DB.executeCommand(DB.java:653) at com.mongodb.DB.command(DB.java:423) at com.mongodb.DB.command(DB.java:439) at com.mongodb.DB.command(DB.java:381) at com.jaspersoft.mongodb.connection.MongoDbConnection.test(MongoDbConnection.java:188) ... 22 moreCaused by: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:210) at java.net.SocketInputStream.read(SocketInputStream.java:141) at com.mongodb.connection.SocketStream.read(SocketStream.java:85) at com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:491) at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:221) ... 41 more</p>