[JAVA-3094] How to handle MongoSocketReadException Created: 15/Nov/18  Updated: 27/Oct/23  Resolved: 15/Nov/18

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

Type: Task Priority: Major - P3
Reporter: Leo Han Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File debug.log     PNG File image-2018-11-15-20-38-44-309.png    
Issue Links:
Related
related to JAVA-1868 MongoDB Java Client gets stuck after ... Closed

 Comments   
Comment by Jeffrey Yemin [ 07/Jan/20 ]

Note also that as of the 3.11 release, the driver also supports retryable reads (retryReads=true in the connection string. Also note that as of the 3.11 release, retryable reads and retryable writes are enabled by default.

Comment by Jeffrey Yemin [ 15/Nov/18 ]

To reiterate, the immediate cause is that the MongoDB server shut down or crashed, or there was a failure somewhere in the network layer. If you enable retryable writes (retryWrites=true in the connection string), the driver will attempt to retry the write on your behalf. For reads, you'll have to catch the exception and execute the retry in the application.

Hope this helps. I'm going to close this issue now, as the driver is working as designed.

Comment by Leo Han [ 15/Nov/18 ]

Hi jeff.yemin, thanks for the input.

In my program I have to put some read and write operations in the loop, is this likely to be the cause of this error?

Regards,Leo

Comment by Jeffrey Yemin [ 15/Nov/18 ]

You're getting the following exception: Caused by: com.mongodb.MongoSocketReadException: Prematurely reached end of stream. This typically happens when the MongoDB server is shut down, and does not indicate a bug in the driver.

If your application needs to be resilient to server restarts, crashes or transient network failures, there are a few things you can do:

  • Utilize the recently added support for retryable writes
  • Execute read operations in a retry loop (support for retryable reads is expected to be added in the next release)
Comment by Leo Han [ 15/Nov/18 ]

Hi jeff.yemin

I uploaded the log file,And I have set the parameters of the connection pool, as follows

Comment by Jeffrey Yemin [ 15/Nov/18 ]

HI leohanchn@gmail.com looks like you hit enter prematurely. Please comment on what the error is, and I'll update the description. Or let me know that you didn't intend to file this issue, and I'll close it out.

Regards,
Jeff

Generated at Thu Feb 08 08:58:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.