From 9800d8e09c406ca8f7f42b4a6cbc7bba1ed69f28 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 23 May 2023 17:43:03 -0400 Subject: [PATCH] docs(connections): add details about `keepAlive` deprecation Re: #13391 --- docs/connections.md | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/docs/connections.md b/docs/connections.md index ab7b588ed3d..5539cfd690a 100644 --- a/docs/connections.md +++ b/docs/connections.md @@ -249,19 +249,9 @@ replica set, Mongoose will emit 'disconnected' if it loses connectivity to the r

A note about keepAlive

-For long running applications, it is often prudent to enable `keepAlive` -with a number of milliseconds. Without it, after some period of time -you may start to see `"connection closed"` errors for what seems like -no reason. If so, after -[reading this](https://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html), -you may decide to enable `keepAlive`: - -```javascript -mongoose.connect(uri, { keepAlive: true, keepAliveInitialDelay: 300000 }); -``` - -`keepAliveInitialDelay` is the number of milliseconds to wait before initiating `keepAlive` on the socket. -`keepAlive` is true by default since mongoose 5.2.0. +Before Mongoose 5.2.0, you needed to enable the `keepAlive` option to initiate [TCP keepalive](https://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html) to prevent `"connection closed"` errors errors. +However, `keepAlive` has been `true` by default since Mongoose 5.2.0, and the `keepAlive` is deprecated as of Mongoose 7.2.0. +Please remove `keepAlive` and `keepAliveInitialDelay` options from your Mongoose connections.

Replica Set Connections