[JAVA-4750] Java Spring Reactive cannot connect to server Created: 05/Oct/22  Updated: 11/Oct/22  Resolved: 11/Oct/22

Status: Closed
Project: Java Driver
Component/s: Reactive Streams
Affects Version/s: 4.0.0
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Tanya C Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File MongoErrorLog.rtf     PNG File Screen Shot 2565-10-11 at 14.06.45.png     PNG File Solution.png     PNG File mongoKibana.png    

 Description   

I would like to get a confirmation and explanation of the root cause of this error below

The Error from mongo : 

1. Mongo Socket Error when Write

Something went wrong org.springframework.dao.DataAccessResourceFailureException: Exception sending message; nested exception is }}com.mongodb.MongoSocketWriteException{{{}: Exception sending message at {}
-------------------------------------------------------------------

2. Mongo Socket Error when Read
com.mongodb.MongoSocketReadException: Prematurely reached end of stream
-------------------------------------------------------------------

3. Follow by no Server chosen

org.mongodb.driver.cluster : No server chosen by com.mongodb.reactivestreams.client.internal.ClientSessionHelper$$Lambda$0000/0x0000000840bf7440@3fcda9a9 from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=MULTIPLE, serverDescriptions=[ServerDescription{address=xxx-dev-xxx-documentdb-0.xxxxxx-xxxxxx.docdb.amazonaws.com:27000, type=UNKNOWN, state=CONNECTING, exception=

{com.mongodb.MongoSocketWriteException: Exception sending message}

, caused by {io.netty.channel.StacklessClosedChannelException}}]}. Waiting for 30000 ms before timing out

Is the root cause can be put as consumption below? and Solution to putting maxIdleTime is correct?

Root caused : 

When the connection is idle for a period of time, the connection is closed due to firewall or load balancing, and the client does not know that, when the client continues to use this closed connection for reading and writing, an error will occur.

If the root cause and solution correct? Is there another way we can see that the connection is lost? In the log, I only see the connection is Open



 Comments   
Comment by Jeffrey Yemin [ 11/Oct/22 ]

tanya.chansataporn@gmail.com I'm going to close this now as it seems more like a support issue and not a problem with the driver itself. If you have further questions, please follow up on either:

  • Our MongoDB support portal, located at support.mongodb.com
  • Our MongoDB community portal, located here
  • If you are an Atlas customer, you can also: Click the in-app chat icon in the lower right corner to chat with a MongoDB Support representative OR Click Support in the left-hand navigation to view Developer Resources.

Just in case you have already opened a support case and are not receiving sufficient help, please let me know and I can facilitate escalating your issue.

Thank you!

Comment by Jeffrey Yemin [ 11/Oct/22 ]

Is there another way we can see that the connection is lost & who cut the connection? In the log, I only see the connection it is Open.

No. Generally you would need either logs from the actual process that closed the connection, or else Wireshark output

if I added (&maxIdleTimeMS=30000) and the error does not appear anymore. Could I imply that the root cause is either Load balancers or firewalls that close idle connections?

That would be a reasonable assumption.

Comment by Tanya C [ 11/Oct/22 ]

Thank you Jeffrey for your reply

I still have questions as below and added more logs as you requested.

Question : 
1. Is there another way we can see that the connection is lost & who cut the connection? In the log, I only see the connection it is Open.
2. if I added  (&maxIdleTimeMS=30000)  and the error does not appear anymore. Could I imply that the root cause is either Load balancers or firewalls that close idle connections?

Attached Kibana log: The Error appears on 14.29

Full-text Error : 
MongoErrorLog.rtf

Refer similar ticket: https://jira.mongodb.org/browse/JAVA-4446

Comment by Jeffrey Yemin [ 08/Oct/22 ]

Load balancers and firewalls that close idle connections are one of many possible root causes of socket errors. With retryable reads and writes enabled in the driver (both are on by default), most operations will be automatically retried and the application will not receive any exceptions.

If a socket error is followed by a server selection timeout error, that means that the retry mechanism failed for some other reason, probably unrelated to this sort of load balancer behavior. You should check server logs and confirm that a primary was actually available during the time period in question. From the looks of that server selection timeout error, the driver is unable to reach the replica set members (though it's hard to say for sure without the full exception message, which looks to be cut off in the description)

Generated at Thu Feb 08 09:02:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.