27 Commits

Author SHA1 Message Date
Charmander
7ef3f4aa4a Fix queued checkout after a connection failure (#111)
* 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>
2018-12-11 12:53:00 -06:00
Charmander
1871d0f9e1 Remove timed-out checkouts from queue correctly (#86)
* Add failing test for correct removal from checkout queue on timeout

* Remove timed-out checkouts from queue correctly

Fixes #85.
2018-05-04 13:04:42 -05:00
Charmander
fabf39c606 Count only test query itself (#87)
* Count only test query itself

This breaks more obviously in PostgreSQL 10 (https://wiki.postgresql.org/wiki/New_in_postgres_10#Significant_Expansion_of_Wait_Events_in_pg_stat_activity).

* Fix query counting for PostgreSQL 9.1
2018-05-04 12:59:39 -05:00
Charmander
4e35226340 Fix client remove clearing unrelated idle timers (#71)
* 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
2017-08-10 09:00:49 -05:00
Brian C
53584b704a Add connection & query timeout if all clients are checked out (#70)
* 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
2017-08-10 00:20:56 -05:00
Brian C
a0eb36d819 2.0 (#67)
* 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
2017-07-13 22:37:08 -05:00
Brian C
f7b1edc7bb Add client to error event emitter (#65)
When the pool emits an error pass the client as the 2nd parameter to the `on('error')` handler.
2017-06-18 14:09:18 -05:00
Brian M. Carlson
5061068b04 Fix test 2017-06-08 18:18:49 -05:00
brianc
959d89e043 Add test for connectionString property delegation 2017-06-07 22:35:55 -05:00
Russ Tyndall
c89b74bb5d Make a test case and fix for errors drainging the pool (#49)
* this bug leaves the pool empty even if there is work
   to be done, if there are enough consecutive errors to
   empty the pool

re brianc/node-pg-pool#48
2017-04-13 08:26:53 -05:00
Charmander
fd802a385c Don’t create promises when callbacks are provided (#31)
* 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`
2016-12-04 17:20:24 -06:00
Yanlong Wang
6a7edabc22 When connection fail, emit the error. (#28)
* When connection fail, emit the error.

If client connect failed, emit the connection error  rather than swallowing it.

* Add test for connection error.
2016-09-13 21:26:03 -05:00
jphaas
b091cc0d05 Bug fix: Pool.query now calls cb if connect() fails (#25)
* 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
2016-08-26 09:08:15 -05:00
Cody Greene
eca2ea0ede emit "connect" event only on success and avoid double callback (#22)
* 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
2016-08-05 16:22:50 -05:00
Cody Greene
51fb7db8fa Support function-like construction (plus test) (#23)
* 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
2016-08-05 16:21:51 -05:00
Brian C
9ab7aff029 Update code to run on >=0.10.0 (#17)
* Replace const with var

* Update code to run on 0.10.x +

* Lint
2016-07-03 18:17:34 -05:00
Brian C
d653234a0c Add acquire event (#16)
* Add acquire event

Add acquire event which fires every time a client is acquired from the pool.

* Update README.md
2016-06-26 22:00:16 -07:00
Brian C
aa1f10b0c0 Add support for pool#query without params (#12) 2016-06-24 11:52:32 -05:00
Brian C
ce59164ba1 Add callback interface to pool#query (#11)
* Add callback interface to pool#query

* Fix linting errors
2016-06-24 11:35:16 -05:00
Brian C
63caf7cd4c Add 'connect' event to pool (#7)
* Have pool emit 'connect' callback with client

* Ensure pool emits client on connect event
2016-06-22 23:29:35 -05:00
Brian C
7ef08fd861 Remove dependency on debug (#6)
Accept a `log: (message, other...) => { }` parameter as a config option, but by default use a no-op function instead of debug.
2016-06-22 23:29:09 -05:00
ikokostya
cc20f8b747 Clone options in Pool constructor (fixes #4) (#5) 2016-06-22 16:34:17 -05:00
Lee Symes
a6f641eb2c Only release client once on an error. (#3)
Prevent `generic-pool` error when releasing a client with an error.

Fixes #2
2016-06-20 19:56:12 -05:00
brianc
cb21c2a2e7 Better compatibility with pg 2016-06-10 22:52:07 -05:00
brianc
2aa207eea6 Update test semantics 2016-06-10 16:58:23 -05:00
brianc
ad73407aad Initial commit 2016-06-08 18:40:32 -05:00
brianc
c0d39055f2 Initial commit 2016-06-07 19:16:19 -05:00