Org.mongodb.driver.cluster: Exception in monitor thread while connecting to server 1

021-02-20 16:37:56.238  INFO 19488 --- [169.4.200:30510] org.mongodb.driver.cluster               : Exception in monitor thread while connecting to server 192.169.4.200:30510

com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message
at com.mongodb.internal.connection.InternalStreamConnection.translateReadException(InternalStreamConnection.java:562) ~[mongodb-driver-core-4.0.5.jar!/:na]
at com.mongodb.internal.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:447) ~[mongodb-driver-core-4.0.5.jar!/:na]
at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:298) ~[mongodb-driver-core-4.0.5.jar!/:na]
at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:258) ~[mongodb-driver-core-4.0.5.jar!/:na]
at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:83) ~[mongodb-driver-core-4.0.5.jar!/:na]
at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:33) ~[mongodb-driver-core-4.0.5.jar!/:na]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:103) ~[mongodb-driver-core-4.0.5.jar!/:na]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:60) ~[mongodb-driver-core-4.0.5.jar!/:na]
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128) ~[mongodb-driver-core-4.0.5.jar!/:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:131) ~[mongodb-driver-core-4.0.5.jar!/:na]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_282]
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_282]
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_282]
at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_282]
at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_282]
at com.mongodb.internal.connection.SocketStream.read(SocketStream.java:109) ~[mongodb-driver-core-4.0.5.jar!/:na]
at com.mongodb.internal.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:579) ~[mongodb-driver-core-4.0.5.jar!/:na]
at com.mongodb.internal.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:444) ~[mongodb-driver-core-4.0.5.jar!/:na]
... 9 common frames omitted

2021-02-20 16:37:58.970  WARN 19488 --- [onPool-worker-4] org.mongodb.driver.connection            : Got socket exception on connection [connectionId{localValue:5, serverValue:104}] to 192.169.4.200:30510. All connections to 192.169.4.200:30510 will be closed.
2021-02-20 16:37:58.993  INFO 19488 --- [onPool-worker-4]  org.mongodb.driver.connection            : Closed connection [connectionId{localValue:5, serverValue:104}] to 192.169.4.200:30510 because there was a socket exception raised by this connection.
2021-02-20 16:37:58.996  INFO 19488 --- [169.4.200:30510] org.mongodb.driver.cluster               : Exception in monitor thread while connecting to server 192.169.4.200:30510

com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) ~[mongodb-driver-core-4.0.5.jar!/:na]
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:127) ~[mongodb-driver-core-4.0.5.jar!/:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) ~[mongodb-driver-core-4.0.5.jar!/:na]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_282]
Caused by: java.net.ConnectException: 拒绝连接 (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_282]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_282]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_282]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_282]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_282]
at java.net.Socket.connect(Socket.java:607) ~[na:1.8.0_282]
at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:63) ~[mongodb-driver-core-4.0.5.jar!/:na]
at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79) ~[mongodb-driver-core-4.0.5.jar!/:na]
at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ~[mongodb-driver-core-4.0.5.jar!/:na]
... 3 common frames omitted

2021-02-20 16:37:59.036  INFO 19488 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-02-20 16:37:59.115 ERROR 19488 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Failed to execute ApplicationRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:789) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:776) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
at ai.plantdata.graph.excel.ExcelApplication.main(ExcelApplication.java:59) [classes!/:1.4.2]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_282]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_282]
at sun.refle

加载更多

any solution for this ?

Hi! Welcome to the forums! So, we would need more clarifying information to help with this. What versions are you using of the Java driver, MongoDB, and Java? What is causing the timeout? Do you have any code to repro steps? And can you be more specific with the question? Thank you.

Any solution for this yet . I am also facing same issue.

Java 11
spring-boot-starter-data-mongodb : 2.6.8
mongodb-driver-sync: 4.4.2
mongodb-driver-core: 4.4.2

MongoAtlas

Steps to reproduce:
Create simple spring boot application , use spring-boot-starter-data-mongodb dependency.
Add mongodtlas connection string in application.properties.
Start application and leave it running for a while.
You can see error in logs.

1 Like

hi, have you solution ? I have the same.

1 Like

spring.data.mongodb.host=hostIpOnWhichMongoIsRunning spring.data.mongodb.port=27017
try putting this in your application.properties

‘‘When a device is assigned a static IP address, the address does not change** . Most devices use dynamic IP addresses, which are assigned by the network when they connect and change over time.’’

So, In your server (MongoDB Atlas) your device in erased.

For this type of error, you just need to go into your cluster in MongoDB atlas and add your current IP address of device

2 Likes

2024-07-28T11:59:58.594+05:30 INFO 44566 — [ngodb.net:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server ac-7x8ck7t-shard-00-01.uzm11lx.mongodb.net:27017

Worked, also nice explanation!