java - Got socket exception on connection [connectionId{localValue:45, serverValue:1893}] to <server IP>. All conn

Getting this mongodb related error in spring-boot 2.0.6.RELEASE. This is happening frequently andwhen

Getting this mongodb related error in spring-boot 2.0.6.RELEASE. This is happening frequently and when making API call, API's where going into pending state. Sometime it is working fine. Want to know why it is happening? How to resolve this?

2025-01-29 09:43:19.509  WARN 110974 --- [io-8081-exec-13] .mongodb.driver.connection            : Got socket exception on connection [connectionId{localValue:45, serverValue:1893}] to 4.213.70.7:27017. All connections to 4.213.70.7:27017 will be closed.
2025-01-29 09:43:19.510  INFO 110974 --- [io-8081-exec-13] .mongodb.driver.connection            : Closed connection [connectionId{localValue:45, serverValue:1893}] to 4.213.70.7:27017 because there was a socket exception raised by this connection.
.springframework.data.mongodb.UncategorizedMongoDbException: Exception receiving message; nested exception is com.mongodb.MongoSocketReadException: Exception receiving message
        at .springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:132)
        at .springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2607)
        at .springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:527)
        at .springframework.data.mongodb.core.MongoTemplate.count(MongoTemplate.java:962)
        at .springframework.data.mongodb.core.MongoTemplate.count(MongoTemplate.java:942)
        at com.cmcp.mongorepository.implementation.WhatsAppTemplateCustomRepositoryImpl.findByCriteria(WhatsAppTemplateCustomRepositoryImpl.java:58)
        at com.cmcp.mongorepository.implementation.WhatsAppTemplateCustomRepositoryImpl$$FastClassBySpringCGLIB$$327a5469.invoke(<generated>)
        at .springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
        at .springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
        at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at .springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
        at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at .springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
        at com.cmcp.mongorepository.implementation.WhatsAppTemplateCustomRepositoryImpl$$EnhancerBySpringCGLIB$$c4a866df.findByCriteria(<generated>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at .springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:377)
        at .springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200)
        at .springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:641)
        at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at .springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:605)
        at .springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:590)
        at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at .springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
        at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at .springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
        at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at .springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
        at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at .springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
        at com.sun.proxy.$Proxy156.findByCriteria(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor456.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)

Getting this mongodb related error in spring-boot 2.0.6.RELEASE. This is happening frequently and when making API call, API's where going into pending state. Sometime it is working fine. Want to know why it is happening? How to resolve this?

2025-01-29 09:43:19.509  WARN 110974 --- [io-8081-exec-13] .mongodb.driver.connection            : Got socket exception on connection [connectionId{localValue:45, serverValue:1893}] to 4.213.70.7:27017. All connections to 4.213.70.7:27017 will be closed.
2025-01-29 09:43:19.510  INFO 110974 --- [io-8081-exec-13] .mongodb.driver.connection            : Closed connection [connectionId{localValue:45, serverValue:1893}] to 4.213.70.7:27017 because there was a socket exception raised by this connection.
.springframework.data.mongodb.UncategorizedMongoDbException: Exception receiving message; nested exception is com.mongodb.MongoSocketReadException: Exception receiving message
        at .springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:132)
        at .springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2607)
        at .springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:527)
        at .springframework.data.mongodb.core.MongoTemplate.count(MongoTemplate.java:962)
        at .springframework.data.mongodb.core.MongoTemplate.count(MongoTemplate.java:942)
        at com.cmcp.mongorepository.implementation.WhatsAppTemplateCustomRepositoryImpl.findByCriteria(WhatsAppTemplateCustomRepositoryImpl.java:58)
        at com.cmcp.mongorepository.implementation.WhatsAppTemplateCustomRepositoryImpl$$FastClassBySpringCGLIB$$327a5469.invoke(<generated>)
        at .springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
        at .springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
        at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at .springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
        at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at .springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
        at com.cmcp.mongorepository.implementation.WhatsAppTemplateCustomRepositoryImpl$$EnhancerBySpringCGLIB$$c4a866df.findByCriteria(<generated>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at .springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:377)
        at .springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200)
        at .springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:641)
        at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at .springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:605)
        at .springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:590)
        at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at .springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
        at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at .springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
        at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at .springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
        at .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at .springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
        at com.sun.proxy.$Proxy156.findByCriteria(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor456.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
Share Improve this question edited Jan 29 at 13:41 Wernfried Domscheit 59.8k10 gold badges90 silver badges128 bronze badges asked Jan 29 at 12:17 VijayVijay 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

The error you're seeing (MongoSocketReadException) usually happens because of network issues or problems with the MongoDB server, like high load or slow responses.

To fix it:

  1. Check MongoDB health: make sure the server is up and stable, and that there are no network issues.

  2. Increase timeouts: in your application.properties, try adjusting the connection and socket timeouts:

    spring.data.mongodb.uri=mongodb://<user>:<password>@<host>:<port>/<db>?socketTimeoutMS=60000&connectTimeoutMS=30000&maxPoolSize=50
    
  3. Monitor connection usage: make sure you're not running out of available connections. Increase the connection pool size if needed.

  4. Update MongoDB driver: if you're not using the latest version, try upgrading it.

These steps should help make your connection more stable and prevent the errors from happening.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745298533a4621292.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信