mongodb / mongodb/mongo-java-driver

Mongo java driver takes a long time detecting an unresponsive mongos

Open
#2,021 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
2.7k
Forks
1.5k
Avg merge
2d 2h
Merged PRs (30d)
10

Description

Hello,
I hope I open this issue in the correct repository. We have run into performance issues with applications taking a long time (minutes) noticing an unresponsive mongos and switching to another one (our mongos are registered in a _mongodb._tcp SRV record).

Trying to tweak socketTimeoutMS has the inconvenient of false positives on slow queries. Could there be another system in the driver that would allow proactively monitoring mongos reactivity? Thanks in advance.

{"exception":{"stacktrace":"com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message\n\tat com.mongodb.internal.connection.InternalStreamConnection.createReadTimeoutException(InternalStreamConnection.java:819)\n\tat com.mongodb.internal.connection.InternalStreamConnection.translateReadException(InternalStreamConnection.java:807)\n\tat com.mongodb.internal.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:857)\n\tat com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:517)\n\tat com.mongodb.internal.connection.InternalStreamConnection.receive(InternalStreamConnection.java:469)\n\tat com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:249)\n\tat com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:176)\nCaused by: java.net.SocketTimeoutException: Read timed out\n\tat java.base\/sun.nio.ch.NioSocketImpl.timedRead(NioSocketImpl.java:278)\n\tat java.base\/sun.nio.ch.NioSocketImpl.implRead(NioSocketImpl.java:304)\n\tat java.base\/sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:346)\n\tat java.base\/sun.nio.ch.NioSocketImpl$1.read(NioSocketImpl.java:796)\n\tat java.base\/java.net.Socket$SocketInputStream.read(Socket.java:1099)\n\tat com.mongodb.internal.connection.SocketStream.read(SocketStream.java:182)\n\tat com.mongodb.internal.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:824)\n\t... 4 more","exception_class":"com.mongodb.MongoSocketReadTimeoutException","exception_message":"Timeout while receiving message"},"source_host":"mp-callback-01-preproduction","method":"info","level":"INFO","message":"Exception in monitor thread while connecting to server mongo-main-02-b.preproduction.*************","mdc":{},"@timestamp":"2026-07-22T12:08:47.463Z","file":"SLF4JLogger.java","line_number":"76","thread_name":"cluster-ClusterId{value='6a6065c9df80181d53fd1b48', description='**********'}-mongo-main-02-b.***************","@version":1,"logger_name":"org.mongodb.driver.cluster","class":"com.mongodb.internal.diagnostics.logging.SLF4JLogger"}
{"exception":{"stacktrace":"com.mongodb.MongoSocketOpenException: Exception opening socket\n\tat com.mongodb.internal.connection.SocketStream.lambda$open$0(SocketStream.java:85)\n\tat java.base\/java.util.Optional.orElseThrow(Optional.java:403)\n\tat com.mongodb.internal.connection.SocketStream.open(SocketStream.java:85)\n\tat com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:233)\n\tat com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:219)\n\tat com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:176)\nCaused by: java.net.SocketTimeoutException: Connect timed out\n\tat java.base\/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:546)\n\tat java.base\/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:592)\n\tat java.base\/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)\n\tat java.base\/java.net.Socket.connect(Socket.java:751)\n\tat com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:76)\n\tat com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:104)\n\tat com.mongodb.internal.connection.SocketStream.open(SocketStream.java:79)\n\t... 3 more","exception_class":"com.mongodb.MongoSocketOpenException","exception_message":"Exception opening socket"},"source_host":"mp-callback-01-preproduction","method":"info","level":"INFO","message":"Exception in monitor thread while connecting to server mongo-main-02-b.*********************","mdc":{},"@timestamp":"2026-07-22T12:20:17.787Z","file":"SLF4JLogger.java","line_number":"76","thread_name":"cluster-ClusterId{value='6a6065c9df80181d53fd1b48', description='***********'}-mongo-main-02-b.**************","@version":1,"logger_name":"org.mongodb.driver.cluster","class":"com.mongodb.internal.diagnostics.logging.SLF4JLogger"}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading DefaultServerMonitor.ServerMonitor, especially lookupServerDescription and the reported SocketStream timeout paths. Trace how SRV-discovered mongos servers are monitored and how failover is triggered. Done requires an agreed proactive monitoring behavior plus tests covering unresponsive mongos detection without false positives from slow queries.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mongodb
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.