-
Notifications
You must be signed in to change notification settings - Fork 10
DOCSP-51408-connection-troubleshooting #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
067cbd2
41ec6b4
81e6d24
27aab4e
e79b211
9b3436c
0a56b51
c39c049
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.. _kotlin-sync-connection-pools: | ||
|
||
================ | ||
Connection Pools | ||
================ | ||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 2 | ||
:class: singlecol | ||
|
||
|
||
.. _kotlin-sync-connection-pool-settings: | ||
|
||
.. TODO |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,308 @@ | ||
.. _kotlin-sync-connection-troubleshooting: | ||
|
||
========================== | ||
Connection Troubleshooting | ||
========================== | ||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 2 | ||
:class: singlecol | ||
|
||
.. facet:: | ||
:name: genre | ||
:values: reference | ||
|
||
.. meta:: | ||
:keywords: code example, disconnected, deployment | ||
|
||
.. sharedinclude:: dbx/connection-troubleshooting.rst | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S: The first line of the Server Connection Errors section reads, "When an issue occurs when you attempt to connect to a server, the Kotlin Sync driver returns an error message." I would make a PR to change the first word of this sentence to "if" ! Small change, but it would be nice to not include so much certainty that there will be an error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll send this PR out for tech review but make a new ticket/PR to reflect this work, as it's in a different repo! |
||
|
||
.. replacement:: non-connection-issue-callout | ||
|
||
.. note:: | ||
|
||
This page addresses only connection issues. If you encounter other | ||
issues when using MongoDB or the driver, visit the following resources: | ||
|
||
- The :ref:`Issues & Help <kotlin-sync-issues-and-help>` page for | ||
information about reporting bugs, contributing to the driver, and | ||
finding more resources | ||
- The :community-forum:`MongoDB Community Forums </tag/kotlin>` for | ||
questions, discussions, or general technical support | ||
|
||
.. replacement:: server-selection-timeout-error | ||
|
||
.. code-block:: none | ||
:copyable: false | ||
|
||
Error: couldn't connect to server 127.0.0.1:27017 | ||
Check failure on line 40 in source/connect/connection-troubleshooting.txt
|
||
|
||
.. replacement:: check-connection-string-anchor | ||
|
||
.. _kotlin-sync-connection-string-port: | ||
|
||
.. replacement:: multiple-hosts-connection-guide-link | ||
|
||
To learn how to specify multiple replica set hosts, see the | ||
:ref:`kotlin-sync-connect-replica-set` section of the Connection Guide. | ||
|
||
.. replacement:: configure-firewall-anchor | ||
|
||
.. _kotlin-sync-connection-firewall: | ||
|
||
.. replacement:: authentication-error-anchor | ||
|
||
.. _kotlin-sync-authentication-error: | ||
|
||
.. replacement:: scram-failure-error | ||
|
||
.. code-block:: none | ||
:copyable: false | ||
|
||
Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server localhost:27017. | ||
|
||
.. replacement:: check-credentials-formatting-anchor | ||
|
||
.. _kotlin-sync-connection-string-auth: | ||
|
||
.. replacement:: learn-more-connection-string-admonition | ||
|
||
.. tip:: | ||
|
||
For more information about using connection strings, | ||
see :ref:`Connection URI <kotlin-sync-connection-uri>` in the Connection Guide. | ||
|
||
.. replacement:: percent-encode-example | ||
|
||
.. replacement:: verify-authentication-database-anchor | ||
|
||
.. _kotlin-sync-verify-auth-db: | ||
|
||
.. replacement:: credentials-provider-alternative-method-description | ||
|
||
If you construct a client by using a ``MongoCredential``, the builder method | ||
corresponds to the authentication mechanism. The following code shows the builder | ||
method for the ``SCRAM-SHA-256`` authentication mechanism: | ||
|
||
.. code-block:: kotlin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is kotlin specific code that differs from the java sync version of this page. |
||
:copyable: false | ||
|
||
val credential = MongoCredential.createScramSha256Credential( | ||
"<db_username>", "<authenticationDb>", "<db_password>".toCharArray() | ||
) | ||
|
||
val settings = MongoClientSettings.builder() | ||
.applyToClusterSettings { builder: ClusterSettings.Builder -> | ||
builder.hosts( | ||
listOf(ServerAddress("<hostname>", <port>)) | ||
) | ||
} | ||
.credential(credential) | ||
.build() | ||
|
||
val mongoClient = MongoClient.create(settings) | ||
|
||
.. replacement:: authentication-guide-reference | ||
|
||
To learn more about specifying authentication mechanisms, see the :ref:`kotlin-sync-auth` | ||
section. | ||
|
||
.. replacement:: verify-authentication-mechanism-anchor | ||
|
||
.. _kotlin-sync-verify-auth-mechanism: | ||
|
||
.. replacement:: authsource-param-code-block | ||
|
||
.. code-block:: kotlin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is Kotlin specific code that differs from the Java version of this page |
||
:copyable: false | ||
|
||
val mongoClient = MongoClient.create("mongodb://<db_username>:<db_password>@<hostname>:<port>/?authSource=users"); | ||
|
||
.. replacement:: dns-resolution-anchor | ||
|
||
.. _kotlin-sync-dns-resolution-error: | ||
|
||
.. replacement:: dns-error-message | ||
|
||
.. code-block:: none | ||
:copyable: false | ||
|
||
com.mongodb.MongoSocketWriteException: Exception sending message | ||
|
||
.. replacement:: check-the-number-of-connections-anchor | ||
|
||
.. _kotlin-sync-connection-num-connections: | ||
|
||
.. replacement:: mongo-client-class | ||
|
||
``MongoClient`` | ||
|
||
.. replacement:: max-pool-size-param | ||
|
||
``maxPoolSize`` | ||
|
||
.. replacement:: max-pool-size-default | ||
|
||
``100`` | ||
|
||
.. replacement:: max-idle-time-param | ||
|
||
``maxIdleTimeMS`` | ||
|
||
.. replacement:: scram-failure-error | ||
|
||
.. code-block:: | ||
|
||
Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server localhost:27017. | ||
|
||
.. replacement:: check-credentials-formatting-anchor | ||
|
||
.. _kotlin-sync-troubleshooting-connection-string-auth: | ||
|
||
.. replacement:: connection-pools-learn-more | ||
|
||
To learn more about how connection pooling works in the driver, see the | ||
:ref:`Connection Pools <kotlin-sync-connection-pools>` page. | ||
|
||
.. _kotlin-sync-timeout-errors: | ||
|
||
Timeout Errors | ||
-------------- | ||
|
||
When you send messages through the driver to the server, sometimes the | ||
messages take a while to respond. When this happens, you might receive an error | ||
message similar to one of the following messages: | ||
|
||
.. code-block:: none | ||
:copyable: false | ||
|
||
Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. | ||
|
||
.. code-block:: none | ||
:copyable: false | ||
|
||
No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description | ||
|
||
If you receive one of these errors, try the following methods to resolve the | ||
issue. | ||
|
||
Set ``maxConnectionTimeoutMS`` | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The ``maxConnectionTimeoutMS`` option indicates the time the {+driver-short+} waits | ||
for a connection before timing out. The default value is ``10000``. You can | ||
increase this value or set it to ``0`` if you want the driver to never timeout. | ||
|
||
Set ``maxConnectionLifeTime`` and ``maxConnectionIdleTime`` | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Consider setting ``maxConnectionLifeTime`` and | ||
``maxConnectionIdleTime``. These parameters configure how long the driver | ||
maintains a connection to a MongoDB instance. For more information about these | ||
parameters, see :ref:`Connection Pool Settings <kotlin-sync-connection-pool-settings>`. | ||
|
||
.. _kotlin-sync-server-selection-errors: | ||
|
||
Server Selection Timeout Exceptions | ||
----------------------------------- | ||
|
||
Your application might not be able to complete a request even when some servers | ||
are available, causing the driver to return a server selection timeout | ||
exception. | ||
|
||
This exception is of type ``MongoTimeoutException``. The following | ||
shows a sample of the exception that occurs if you attempt to send a | ||
request to a replica set in which the primary is not reachable: | ||
|
||
.. code-block:: none | ||
|
||
com.mongodb.MongoTimeoutException: | ||
Timed out while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. | ||
Client view of cluster state is | ||
{type=REPLICA_SET, | ||
servers=[ | ||
{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused}}, | ||
{address=localhost:27018, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused}}, | ||
{address=localhost:27019, type=REPLICA_SET_SECONDARY, roundTripTime=15.0 ms, state=CONNECTED} | ||
] | ||
} | ||
|
||
The error includes a view of the cluster state that describes the | ||
connection state of each node, which can help you identify the source of | ||
your connection issue. | ||
|
||
In the preceding error, the only connected server, ``localhost:27019``, | ||
is a secondary node. Because of this, the request times out as the | ||
driver is unable to select a server that satisfies the read preference | ||
of ``primary``. In this situation, you can still perform read operations | ||
against the connected secondary node if you set the read preference to | ||
``secondary``, ``secondaryPreferred``, or ``nearest``. | ||
|
||
You can also specify the ``serverSelectionTimeoutMS`` connection option | ||
to adjust the amount of time in which the driver must select a server. To | ||
learn more, see the :ref:`kotlin-sync-connection-options` guide. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I: Make sure the Connection Options page is clickable as a landing page in the TOC. |
||
|
||
.. _kotlin-sync-miscellaneous-errors: | ||
|
||
Miscellaneous Errors | ||
-------------------- | ||
|
||
This section shows connection errors that do not fall into a broader category. | ||
|
||
Monitor Thread Exception | ||
~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. code-block:: none | ||
:copyable: false | ||
|
||
INFO: Exception in monitor thread while connecting to server ssc-cluster-01-shard-00-02.9cbnp.mongodb.net:27017 | ||
|
||
This log line indicates that the monitor that continuously | ||
checks the status of each replica set member or ``mongos`` server failed to | ||
contact one of the nodes or servers. This is an expected message during server | ||
maintenance operations and can be safely ignored. | ||
|
||
Certificate Request Exception | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. code-block:: none | ||
:copyable: false | ||
|
||
javax.net.ssl.SSLHandshakeException: extension (5) should not be presented in certificate_request | ||
Check failure on line 273 in source/connect/connection-troubleshooting.txt
|
||
|
||
This is a known issue in certain versions of the JDK that can occur when | ||
attempting to connect by using the TLS 1.3 protocol. | ||
|
||
If you encounter this error when connecting to your MongoDB instance or | ||
cluster, update your JDK to one of the following patch versions or newer: | ||
|
||
- JDK 11.0.7 | ||
- JDK 13.0.3 | ||
- JDK 14.0.2 | ||
|
||
To learn more about this issue, see the | ||
`issue description <https://bugs.openjdk.java.net/browse/JDK-8236039>`__ | ||
in the OpenJDK Bug system tracker issue. | ||
|
||
.. _kotlin-sync-debugging-tips: | ||
|
||
Debugging Tips | ||
-------------- | ||
|
||
While not related to a specific error message, this section includes | ||
information that can help in the process of troubleshooting connection | ||
issues. | ||
|
||
Verbose Logging for TLS/SSL | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
You can use the ``-Djavax.net.debug=all`` system property to enable | ||
debug-level logging related to all connections, including those | ||
established by using TLS/SSL. | ||
|
||
Enabling debug-level logging can help you diagnose the root problem of | ||
connection issues. To learn more about the TLS/SSL logging messages, | ||
see the `Debugging SSL/TLS Connections <https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/ReadDebug.html>`__ | ||
Java documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for reviewer: this page is almost identical to https://www.mongodb.com/docs/drivers/java/sync/current/connection/connection-troubleshooting/ except for two code examples that I've commented on below.