Skip to content
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

docs(connections): add details about keepAlive deprecation #13431

Merged
merged 1 commit into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 3 additions & 13 deletions docs/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,9 @@ replica set, Mongoose will emit 'disconnected' if it loses connectivity to the r

<h2 id="keepAlive"><a href="#keepAlive">A note about keepAlive</a></h2>

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think double "errors" is not quite right here

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.

<h2 id="replicaset_connections"><a href="#replicaset_connections">Replica Set Connections</a></h2>

Expand Down