-
Notifications
You must be signed in to change notification settings - Fork 20
DOCSP-30724: Connection Troubleshooting page #115
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
Merged
nickldp
merged 7 commits into
mongodb:master
from
nickldp:DOCSP-30724-connection-troubleshooting-page
Jul 14, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4583f30
DOCSP-30724: Connection Troubleshooting page
nickldp 29095be
add index
nickldp c4a68b4
self review
nickldp d15c8cd
quick fix
nickldp 9d72234
anotha one
nickldp 8d26e2f
last one
nickldp c11d217
post review
nickldp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,235 @@ | ||
| .. _kotlin-connection-troubleshooting: | ||
|
|
||
| ========================== | ||
| Connection Troubleshooting | ||
| ========================== | ||
|
|
||
| .. contents:: On this page | ||
| :local: | ||
| :backlinks: none | ||
| :depth: 2 | ||
| :class: singlecol | ||
|
|
||
| This page offers potential solutions to issues you might see when | ||
| connecting to a MongoDB instance or replica set while using the | ||
| {+driver-long+}. | ||
|
|
||
| .. note:: | ||
|
|
||
| This page lists only connection issues. If you are having any other issues | ||
| with MongoDB, consider the following resources: | ||
|
|
||
| - The :ref:`Frequently Asked Questions (FAQ) <kotlin-faq>` for the {+driver-short+} | ||
| - The :ref:`Issues & Help <kotlin-issues-and-help>` topic for information about | ||
| reporting bugs, contributing to the driver, and additional resources | ||
| - The `MongoDB Community Forums <https://community.mongodb.com>`__ for | ||
| questions, discussions, or general technical support | ||
|
|
||
| Connection Error | ||
| ~~~~~~~~~~~~~~~~ | ||
|
|
||
| The following error message is a general message indicating that the driver | ||
| cannot connect to a server on the specified hostname or port: | ||
|
|
||
| .. code-block:: none | ||
| :copyable: false | ||
|
|
||
| Error: couldn't connect to server 127.0.0.1:27017 | ||
|
|
||
| If you receive this error, try the following methods to resolve the issue. | ||
|
|
||
| .. _kotlin-connection-string-port: | ||
|
|
||
| Check Connection String | ||
| ----------------------- | ||
|
|
||
| Verify that the hostname and port number in the connection string are both | ||
| accurate. In the sample error message, the hostname is ``127.0.0.1`` and the | ||
| port is ``27017``. The default port value for a MongoDB instance is | ||
| ``27017``, but you can configure MongoDB to communicate on another port. | ||
|
|
||
| .. _kotlin-connection-firewall: | ||
|
|
||
| Configure Firewall | ||
| ------------------ | ||
|
|
||
| Assuming that your MongoDB deployment uses the default port, verify that your | ||
| firewall has port ``27017`` open. If your deployment is using a different port, | ||
| verify that port is open in your firewall. | ||
|
|
||
| .. important:: | ||
|
|
||
| Do not open ports in your firewall unless you are sure that is the port used | ||
| by your MongoDB instance. | ||
|
|
||
| Authentication Error | ||
| ~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| The {+driver-short+} can fail to connect to a MongoDB instance if | ||
| the authorization is not configured correctly. This often results in an error | ||
| message similar to the following: | ||
|
|
||
| .. code-block:: none | ||
| :copyable: false | ||
|
|
||
| Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server localhost:27017. | ||
|
|
||
| If you receive this error, try the following methods to resolve the issue. | ||
|
|
||
| .. _kotlin-connection-string-auth: | ||
|
|
||
| Check Connection String | ||
| ----------------------- | ||
|
|
||
| An invalid connection string is the most common cause of authentication | ||
| issues when attempting to connect to MongoDB. | ||
|
|
||
| .. note:: | ||
|
|
||
| For more information about using connection strings with the {+driver-short+}, | ||
| see :ref:`Connection URI <connection-uri>` in the Connection Guide. | ||
|
|
||
| If your connection string contains a username and password, ensure that they | ||
| are in the correct format. | ||
|
|
||
| .. note:: | ||
|
|
||
| If the username or password includes any of the following characters, they | ||
| must be `percent encoded <https://tools.ietf.org/html/rfc3986#section-2.1>`__: | ||
|
|
||
| .. code-block:: none | ||
|
|
||
| : / ? # [ ] @ | ||
|
|
||
|
|
||
| If your MongoDB deployment is on MongoDB Atlas, you can check your connection | ||
| string by using the :ref:`Atlas Connection Example <connect-atlas-kotlin-driver>`. | ||
| Make sure to replace the connection string in the example with yours. | ||
|
|
||
| When connecting to a replica set, you should include all of the hosts | ||
| in the replica set in your connection string. Separate each of the hosts | ||
| in the connection string with a comma. This enables the driver to establish a | ||
| connection if one of the hosts is unreachable. | ||
|
|
||
| .. _kotlin-connection-admin: | ||
|
|
||
| Verify User Is in Authentication Database | ||
| ----------------------------------------- | ||
|
|
||
| To successfully authenticate a connection by using a username and password, | ||
| the username must be defined in the authentication database. The default | ||
| authentication database is the ``admin`` database. To use a different database | ||
| for authentication, specify the ``authSource`` in the connection string. The | ||
| following example instructs the driver to use ``users`` as the authentication | ||
| database: | ||
|
|
||
| .. code-block:: kotlin | ||
| :copyable: false | ||
|
|
||
| val mongoClient = | ||
| MongoClient.create("mongodb://<username>:<password>@<hostname>:<port>/?authSource=users") | ||
|
|
||
| .. _kotlin-error-sending-message: | ||
|
|
||
| Error Sending Message | ||
| ~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| When you send a request through the driver and it is unable to send the command, | ||
| it often displays the following general error message: | ||
|
|
||
| .. code-block:: none | ||
| :copyable: false | ||
|
|
||
| com.mongodb.MongoSocketWriteException: Exception sending message | ||
|
|
||
| If you receive this error, try the following methods to resolve the issue. | ||
|
|
||
| Check Connection String | ||
| ----------------------- | ||
|
|
||
| Verify that the connection string in | ||
| your app is accurate. This is described under :ref:`Connection Error <kotlin-connection-string-port>` | ||
| and :ref:`Authentication Error <kotlin-connection-string-auth>`. | ||
|
|
||
| Verify User Is in Authentication Database | ||
| ----------------------------------------- | ||
|
|
||
| The user needs to be recognized in your | ||
| authentication database. This is described under :ref:`Authentication | ||
| Error <kotlin-connection-admin>`. | ||
|
|
||
| Configure Firewall | ||
| ------------------ | ||
|
|
||
| The firewall needs to have an open port for communicating with the MongoDB | ||
| instance. This is described under :ref:`Connection Error <kotlin-connection-firewall>`. | ||
|
|
||
| .. _kotlin-connection-number-connections: | ||
|
|
||
| Check the Number of Connections | ||
| ------------------------------- | ||
|
|
||
| Each ``MongoClient`` instance supports a maximum number of concurrent open | ||
| connections in its connection pool. The configuration parameter ``maxPoolSize`` | ||
| defines this value and is set to ``100`` by default. If there are already a | ||
| number of open connections equal to ``maxPoolSize``, the server waits until | ||
| a connection becomes available. If this wait time exceeds the ``maxIdleTimeMS`` | ||
| value, the driver responds with an error. | ||
|
|
||
| Timeout Error | ||
| ~~~~~~~~~~~~~ | ||
|
|
||
| Sometimes when you send messages through the driver to the server, the messages | ||
| take a while to respond. When this happens, you might receive an error message | ||
| similar to one of the following error 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 amount of 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 a connection | ||
| can be maintained with a MongoDB instance. For more information about these | ||
| parameters, see :ref:`Connection Pool Settings <mcs-connectionpool-settings>`. | ||
|
|
||
| Check the Number of Connections | ||
| ------------------------------- | ||
|
|
||
| You might have too many open connections. The solution to this is described | ||
| under :ref:`Error Sending Message <kotlin-error-sending-message>`. | ||
|
|
||
| Additional Tips | ||
| ~~~~~~~~~~~~~~~ | ||
|
|
||
| While not related to a specific error message, this section includes | ||
| additional information that can be useful when attempting to troubleshoot | ||
| connection issues. | ||
|
|
||
| Get Log Information for TLS/SSL | ||
| ------------------------------- | ||
|
|
||
| When using TLS/SSL, you can use the ``-Djavax.net.debug=all`` system property | ||
| to view additional log statements. This can help when attempting to debug any | ||
| connection issues. See `the Oracle guide to debugging TLS/SSL connections | ||
| <https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/ReadDebug.html>`__ | ||
| for more information. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| .. _kotlin-issues-and-help: | ||
|
|
||
| ============= | ||
| Issues & Help | ||
| ============= | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
S: add a note to this page linking to the connection troubleshooting guide like the java one has: https://github.com/mongodb/docs-java/blob/6b87e5d49f837d6f1d9a16909d09df58828278a5/source/faq.txt#L18-L23