Skip to content

Commit 67cb1f2

Browse files
committed
docs: enhance the pool.end() behavior description
closes #1803
1 parent e8fea70 commit 67cb1f2

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

Readme.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,28 @@ pool.end(function (err) {
457457
```
458458

459459
The `end` method takes an _optional_ callback that you can use to know once
460-
all the connections have ended. The connections end _gracefully_, so all
461-
pending queries will still complete and the time to end the pool will vary.
460+
all the connections have ended.
462461

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

465+
This works by calling `connection.end()` on every active connection in the
466+
pool, which queues a `QUIT` packet on the connection. And sets a flag to
467+
prevent `pool.getConnection` from continuing to create any new connections.
468+
469+
Since this queues a `QUIT` packet on each connection, all commands / queries
470+
already in progress will complete, just like calling `connection.end()`. If
471+
`pool.end` is called and there are connections that have not yet been released,
472+
those connections will fail to execute any new commands after the `pool.end`
473+
since they have a pending `QUIT` packet in their queue; wait until releasing
474+
all connections back to the pool before calling `pool.end()`.
475+
476+
Since the `pool.query` method is a short-hand for the `pool.getConnection` ->
477+
`connection.query` -> `connection.release()` flow, calling `pool.end()` before
478+
all the queries added via `pool.query` have completed, since the underlying
479+
`pool.getConnection` will fail due to all connections ending and not allowing
480+
new connections to be created.
481+
466482
## PoolCluster
467483

468484
PoolCluster provides multiple hosts connection. (group & retry & selector)

0 commit comments

Comments
 (0)