Skip to content

Commit 6e76f2e

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 b501674 commit 6e76f2e

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
@@ -204,6 +204,47 @@ Consider setting ``maxConnectionLifeTime`` and
204204
maintains a connection to a MongoDB instance. For more information about these
205205
parameters, see :ref:`Connection Pool Settings <mcs-connectionpool-settings>`.
206206

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

209250
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)