Skip to content

Commit 63857dc

Browse files
committed
DOCSP-26065: socketTimeoutMS behavior (#643)
* DOCSP-26065: update information related to socketTimeoutMS + other fixes * link fix * fix * changes after CC discussion * wording * CC PR fixes 1 * CC suggestion (cherry picked from commit 4646875)
1 parent 8b2d9c0 commit 63857dc

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

source/faq.txt

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -84,33 +84,32 @@ is on the other side of the planet and has a latency of 10000
8484
milliseconds, setting the ``connectTimeoutMS`` to anything lower will
8585
prevent the driver from ever connecting to that member.
8686

87-
Should I Use "socketTimeoutMS" as a Way of Preventing Long-Running Operations From Slowing Down the Server?
88-
-------------------------------------------------------------------------------------------------------------
87+
What Happens to Running Operations If the Client Disconnects?
88+
-------------------------------------------------------------
8989

90-
No, you should **not** use ``socketTimeoutMS`` to end operations that
91-
may run for too long and slow down the application. Attempting to do so
92-
may not achieve the intended result.
90+
Starting in {+mdb-server+} version 4.2, the server terminates
91+
running operations such as aggregations and find operations if the
92+
client disconnects. To see a full list of operations affected by this
93+
behavior, see the :manual:`Server version 4.2 release notes
94+
</release-notes/4.2/#client-disconnection>` in the Server manual.
9395

94-
Closing the socket causes a reconnect of the driver's connection pool,
95-
introducing latency to any other queued up operations. Chronically slow
96-
operations will, therefore, cause a large number of reconnect requests,
97-
negatively impacting throughput and performance.
96+
Other operations, such as write operations, continue to run on the
97+
{+mdb-server+} even if the client disconnects. This behavior can cause data
98+
inconsistencies if your application retries the operation after the
99+
client disconnects.
98100

99-
Also, closing the socket does not terminate the operation; it will
100-
continue to run on the MongoDB server, which could cause data
101-
inconsistencies if the application retries the operation on failure.
101+
How Can I Confirm That the Driver Closed Unusable Sockets?
102+
----------------------------------------------------------
102103

103-
However, there are important use cases for ``socketTimeoutMS`` -
104-
consider the following cases:
104+
If you experience unexpected network behavior or if a MongoDB process
105+
fails with an error, you may not receive confirmation that the
106+
driver correctly closed the corresponding socket.
105107

106-
- A MongoDB process erroring out
107-
- A misconfigured firewall causing a socket connection without sending a ``FIN`` packet
108-
109-
In those cases, there is no way to detect that the connection has died.
110-
Setting the ``socketTimeoutMS`` is essential to ensure that the sockets
111-
are closed correctly. A good rule of thumb is to set ``socketTimeoutMS``
112-
to two to three times the length of the slowest operation that runs
113-
through the driver.
108+
To make sure that the driver correctly closes the socket in these cases,
109+
set the ``socketTimeoutMS`` option. When a MongoDB process times out, the driver
110+
will close the socket. We recommend that you select a value
111+
for ``socketTimeoutMS`` that is two to three times as long as the
112+
expected duration of the slowest operation that your application executes.
114113

115114
How Can I Prevent Sockets From Timing out Before They Become Active?
116115
--------------------------------------------------------------------
@@ -127,18 +126,19 @@ avoid closing.
127126

128127
One message every 3000 milliseconds is not enough to keep the sockets
129128
active, so several of the sockets will time out after 5000 milliseconds.
130-
Reduce the ``poolSize`` in the connection settings to fix the problem.
129+
To avoid excessive socket timeouts, reduce the number of connections
130+
that the driver can maintain in the connection pool by specifying the
131+
``maxPoolSize`` option.
131132

132-
To specify the optional ``poolSize`` setting for your ``MongoClient``, declare
133+
To specify the optional ``maxPoolSize`` setting for your ``MongoClient``, declare
133134
it in the ``options`` object of the constructor as follows:
134135

135136
.. code-block:: javascript
136137

137138
const client = new MongoClient(uri, {
138-
poolSize: <integer value>,
139+
maxPoolSize: <integer value>,
139140
});
140141

141-
142142
What Does a Value of "0" mean for "connectTimeoutMS" and "socketTimeoutMS"?
143143
---------------------------------------------------------------------------
144144

@@ -216,7 +216,7 @@ How Can I Prevent a Slow Operation From Delaying Other Operations?
216216
------------------------------------------------------------------
217217

218218
A slow operation may delay your other operations that occur after it, if
219-
the ``poolSize`` has not been set in the
219+
the ``maxPoolSize`` has not been set in the
220220
:ref:`connection options <node-connection-options>`.
221221
MongoDB is synchronous and uses a single execution thread per socket,
222222
meaning that MongoDB will execute one single operation per socket at any
@@ -227,9 +227,9 @@ a separate connection pool for the slow operation, isolating it from
227227
other, faster operations.
228228

229229
.. note::
230-
If the number of operations is greater than the set ``poolSize`` and
231-
a slow operation occurs, subsequent operations will be delayed.
232-
230+
If the number of operations is greater than the value of the
231+
``maxPoolSize`` option and a slow operation occurs, subsequent
232+
operations will be delayed.
233233

234234
To create a separate connection pool, instantiate another ``MongoClient``
235235
call the ``connect()`` method on it. See the following example for the

0 commit comments

Comments
 (0)