Skip to content

Commit 6688028

Browse files
committed
DOCSP-30349: server selection errors (#548)
* DOCSP-30349: server sel errors * NR PR fixes 1 * JY tech review * fixes * anchor * vale fix (cherry picked from commit aad1fae)
1 parent d177f66 commit 6688028

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

source/connection-troubleshooting.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,47 @@ Consider setting ``maxConnectionLifeTime`` and
203203
maintains a connection to a MongoDB instance. For more information about these
204204
parameters, see :ref:`Connection Pool Settings <mcs-connectionpool-settings>`.
205205

206+
.. _java-server-selection-errors:
207+
208+
Server Selection Timeout Exceptions
209+
-----------------------------------
210+
211+
Your application might not be able to complete a request even when some servers
212+
are available, causing the driver to return a server selection timeout
213+
exception.
214+
215+
This exception is of type ``MongoTimeoutException``. The following
216+
shows a sample of the exception that occurs if you attempt to send a
217+
request to a replica set in which the primary is not reachable:
218+
219+
.. code-block:: none
220+
221+
com.mongodb.MongoTimeoutException:
222+
Timed out while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}.
223+
Client view of cluster state is
224+
{type=REPLICA_SET,
225+
servers=[
226+
{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused}},
227+
{address=localhost:27018, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused}},
228+
{address=localhost:27019, type=REPLICA_SET_SECONDARY, roundTripTime=15.0 ms, state=CONNECTED}
229+
]
230+
}
231+
232+
The error includes a view of the cluster state that describes the
233+
connection state of each node, which can help you identify the source of
234+
your connection issue.
235+
236+
In the preceding error, the only connected server, ``localhost:27019``,
237+
is a secondary node. Because of this, the request times out as the
238+
driver is unable to select a server that satisfies the read preference
239+
of ``primary``. In this situation, you can still perform read operations
240+
against the connected secondary node if you set the read preference to
241+
``secondary``, ``secondaryPreferred``, or ``nearest``.
242+
243+
You can also specify the ``serverSelectionTimeoutMS`` connection option
244+
to adjust the amount of time in which the driver must select a server. To
245+
learn more, see the :ref:`java-connection-options` guide.
246+
206247
.. _java-miscellaneous-errors:
207248

208249
Miscellaneous Errors

source/fundamentals/connection/connection-options.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.. _java-connection-options:
12
.. _connection-options:
23

34
==================

0 commit comments

Comments
 (0)