Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 13 additions & 22 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,28 +455,19 @@ pool.end(function (err) {
});
```

The `end` method takes an _optional_ callback that you can use to know once
all the connections have ended.

**Once `pool.end()` has been called, `pool.getConnection` and other operations
can no longer be performed**

This works by calling `connection.end()` on every active connection in the
pool, which queues a `QUIT` packet on the connection. And sets a flag to
prevent `pool.getConnection` from continuing to create any new connections.

Since this queues a `QUIT` packet on each connection, all commands / queries
already in progress will complete, just like calling `connection.end()`. If
`pool.end` is called and there are connections that have not yet been released,
those connections will fail to execute any new commands after the `pool.end`
since they have a pending `QUIT` packet in their queue; wait until releasing
all connections back to the pool before calling `pool.end()`.

Since the `pool.query` method is a short-hand for the `pool.getConnection` ->
Copy link
Member

Choose a reason for hiding this comment

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

Can you find a spot to keep the note about it being a short-hand for the three methods? A user previously added that part to this section because they were confused without it. I would like to keep it there for them if possible.

`connection.query` -> `connection.release()` flow, calling `pool.end()` before
all the queries added via `pool.query` have completed, since the underlying
`pool.getConnection` will fail due to all connections ending and not allowing
new connections to be created.
The `end` method takes an _optional_ callback that you can use to know when
all the connections are ended.

**Once `pool.end` is called, `pool.getConnection` and other operations
can no longer be performed.** Wait until all connections in the pool are
released before calling `pool.end`. If you use the shortcut method
`pool.query`, in place of `pool.getConnection` → `connection.query` →
`connection.release`, wait until it completes.

`pool.end` calls `connection.end` on every active connection in the pool.
This queues a `QUIT` packet on the connection and sets a flag to prevent
`pool.getConnection` from creating new connections. All commands / queries
already in progress will complete, but new commands won't execute.

## PoolCluster

Expand Down