org.springframework.data.mongodb.UncategorizedMongoDbException: Exception receiving message; nested exception is com.mongodb.MongoSocketReadException: Exception receiving message at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:107) at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2114) at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:464) at org.springframework.data.mongodb.core.MongoTemplate.saveDBObject(MongoTemplate.java:1080) at org.springframework.data.mongodb.core.MongoTemplate.doSave(MongoTemplate.java:1015) at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:961) at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:949) at com.foundation.mongo.dao.impl.MongoBaseDaoImpl.save(MongoBaseDaoImpl.java:108) at com.foundation.service.record.service.impl.BaseRecordServiceImpl.saveRecord(BaseRecordServiceImpl.java:33) at com.foundation.service.record.service.impl.IndicatorRecordService.saveIndicator(IndicatorRecordService.java:47) at com.foundation.service.record.service.impl.IndicatorRecordService.saveIndicators(IndicatorRecordService.java:119) at com.foundation.service.record.service.impl.IndicatorRecordService$$FastClassBySpringCGLIB$$56955274.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) at com.foundation.service.record.service.impl.IndicatorRecordService$$EnhancerBySpringCGLIB$$d2c761dd.saveIndicators(<generated>) at com.foundation.service.canal.listener.BusiSyncHandle.syncBusiExamValue(BusiSyncHandle.java:741) at com.foundation.service.canal.listener.BusiSyncHandle$$FastClassBySpringCGLIB$$57f9d56c.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) at com.foundation.service.canal.listener.BusiSyncHandle$$EnhancerBySpringCGLIB$$cf8285c5.syncBusiExamValue(<generated>) at com.foundation.service.canal.listener.BusiAnscWatcherThread.gotoSyncData(BusiAnscWatcherThread.java:232) at com.foundation.service.canal.listener.BusiAnscWatcherThread.dealBusinessData(BusiAnscWatcherThread.java:181) at com.foundation.service.canal.listener.BusiAnscWatcherThread.switchHandle(BusiAnscWatcherThread.java:149) at com.foundation.service.canal.listener.BusiAnscWatcherThread.init(BusiAnscWatcherThread.java:89) at com.foundation.service.canal.listener.BusiAnscWatcherThread.run(BusiAnscWatcherThread.java:53) Caused by: com.mongodb.MongoSocketReadException: Exception receiving message at com.mongodb.connection.InternalStreamConnection.translateReadException(InternalStreamConnection.java:481) at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:226) at com.mongodb.connection.UsageTrackingInternalConnection.receiveMessage(UsageTrackingInternalConnection.java:105) at com.mongodb.connection.DefaultConnectionPool$PooledConnection.receiveMessage(DefaultConnectionPool.java:438) at com.mongodb.connection.WriteCommandProtocol.receiveMessage(WriteCommandProtocol.java:262) at com.mongodb.connection.WriteCommandProtocol.execute(WriteCommandProtocol.java:104) at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:67) at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:37) at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:168) at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:289) at com.mongodb.connection.DefaultServerConnection.insertCommand(DefaultServerConnection.java:118) at com.mongodb.operation.InsertOperation.executeCommandProtocol(InsertOperation.java:76) at com.mongodb.operation.BaseWriteOperation$1.call(BaseWriteOperation.java:142) at com.mongodb.operation.BaseWriteOperation$1.call(BaseWriteOperation.java:134) at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:232) at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:223) at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:134) at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:61) at com.mongodb.Mongo.execute(Mongo.java:827) at com.mongodb.Mongo$2.execute(Mongo.java:810) at com.mongodb.DBCollection.executeWriteOperation(DBCollection.java:333) at com.mongodb.DBCollection.insert(DBCollection.java:328) at com.mongodb.DBCollection.insert(DBCollection.java:319) at com.mongodb.DBCollection.insert(DBCollection.java:289) at com.mongodb.DBCollection.insert(DBCollection.java:255) at com.mongodb.DBCollection.insert(DBCollection.java:177) at com.mongodb.DBCollection.save(DBCollection.java:398) at com.mongodb.DBCollection.save(DBCollection.java:373) at org.springframework.data.mongodb.core.MongoTemplate$11.doInCollection(MongoTemplate.java:1085) at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:462) ... 38 more Caused by: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:196) at java.net.SocketInputStream.read(SocketInputStream.java:122) at com.mongodb.connection.SocketStream.read(SocketStream.java:85) at com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:492) at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:222) ... 66 more
配置信息如下:
<!-- 开启注解 --> <context:property-placeholder location="classpath:mongodb.properties" ignore-unresolvable="true"/> <mongo:mongo-client host="${mongo.host}" port="${mongo.port}" id="mongo"> </mongo:mongo-client> <mongo:db-factory id="mongoDbFactory" dbname="${mongo.dbname}" mongo-ref="mongo" />
有可能是程序获取到了已关闭的连接,比如线程池一个连接长时间未使用,导致断开,这时获取到这个连接再使用的时候就会报这个错误,
<spanstyle="color:#e8bf6a;"><<spanstyle="color:#9876aa;">mongo<spanstyle="color:#e8bf6a;">:client-options<spanstyle="color:#e8bf6a;"><spanstyle="color:#bababa;">connections-per-host<spanstyle="color:#a5c261;">="500"<spanstyle="color:#a5c261;"><spanstyle="color:#bababa;">threads-allowed-to-block-for-connection-multiplier<spanstyle="color:#a5c261;">="50"<spanstyle="color:#a5c261;"><spanstyle="color:#bababa;">connect-timeout<spanstyle="color:#a5c261;">="10000"<spanstyle="color:#a5c261;"><spanstyle="color:#bababa;">max-wait-time<spanstyle="color:#a5c261;">="25000"<spanstyle="color:#a5c261;"><spanstyle="color:#bababa;">socket-keep-alive<spanstyle="color:#a5c261;">="true"<spanstyle="color:#a5c261;"><spanstyle="color:#bababa;">socket-timeout<spanstyle="color:#a5c261;">="0"<spanstyle="color:#e8bf6a;">/>
我设置了一下参数,这个问题到目前为之,就没有再出现过了。后续再跟踪一下。应该是设置的
<spanstyle="color:#BABABA;">socket-timeout<spanstyle="color:#A5C261;">="0"起了作用
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。