* Test queued checkout after a connection failure
Co-authored-by: Johannes Würbach <johannes.wuerbach@googlemail.com>
* Fix queued checkout after a connection failure
Co-authored-by: Johannes Würbach <johannes.wuerbach@googlemail.com>
* Add failing test for idle timer continuation after removal
* Clear idle timeout only for removed client
* Copy list of idle clients for modification during iteration
* Add connection & query timeout if all clients are checked out
This addresses [pg#1390](https://github.com/brianc/node-postgres/issues/1390).
Ensure connection timeout applies both for new connections and on an exhuasted pool. I also made the library return an error when passing a function as the first param to `pool.query` - previosuly this threw a sync type error.
* Add pg-cursor to dev deps
* Initial work
* Make progress on custom pool
* Make all original tests pass
* Fix test race
* Fix test when DNS is missing
* Test more error conditions
* Add test for byop
* Add BYOP tests for errors
* Add test for idle client error expunging
* Fix typo
* Replace var with const/let
* Remove var usage
* Fix linting
* Work on connection timeout
* Work on error condition tests
* Remove logging
* Add connection timeout
* Add idle timeout
* Test for returning to client to pool after error
fixes#48
* Add idleTimeout support to native client
* Add pg as peer dependency
fixes#45
* Rename properties
* Fix lint
* use strict
* Add draining to pool.end
* Ensure ending pools drain properly
* Remove yarn.lock
* Remove object-assign
* Remove node 8
* Remove closure for waiter construction
* Ensure client.connect is never sync
* Fix lint
* Change to es6 class
* Code cleanup & lint fixes
* Revert "When connection fail, emit the error. (#28)"
This reverts commit 6a7edabc22e36db7386c97ee93f08f957364f37d.
The callback passed to `Pool.prototype.connect` should be responsible for handling connection errors. The `error` event is documented to be:
> Emitted whenever an idle client in the pool encounters an error.
This isn’t the case of an idle client in the pool; it never makes it into the pool.
It also breaks tests on pg’s master because of nonspecific dependencies.
* Don’t create promises when callbacks are provided
It’s incorrect to do so. One consequence is that a rejected promise will be unhandled, which is currently annoying, but also dangerous in the future:
> DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
The way callbacks are used currently also causes #24 (hiding of errors thrown synchronously from the callback). One fix for that would be to call them asynchronously from inside the `new Promise()` executor:
process.nextTick(cb, error);
I don’t think it’s worth implementing, though, since it would still be backwards-incompatible – just less obvious about it.
Also fixes a bug where the `Pool.prototype.connect` callback would be called twice if there was an error.
* Use Node-0.10-compatible `process.nextTick`
* When connection fail, emit the error.
If client connect failed, emit the connection error rather than swallowing it.
* Add test for connection error.
* Pool.query calls cb if connect() fails
Old behavior was that if connect called back with an error, the promise would get rejected but the cb function would never get called.
* Test that Pool.query passes connection errors to callback
* Fixes to standardjs compliance
* fail: "connect" event only on success
Double callback invocation will also cause this to fail.
* avoid double callback: _create
If `client.connect` returns an error, then the callback for `Pool#_create` is only invoked once. Also the `connect` event is only emitted on a successful connection, the client is otherwise rather useless.
* legacy compat; don't use Object.assign
* legacy compat; events.EventEmitter
* Support function-like construction
Remove the necessity of using `new` in front of the `Pool`, i.e. allow it to be used as a regular function. This is following https://github.com/brianc/node-postgres/issues/1077
* add Pool factory test