81 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
Brian M. Carlson
4b9669eaa7 Bump version 2018-11-12 12:32:19 -06:00
Yuval Greenfield
277dc508da Clarifying pool connect logging (#73)
Existing log code was outputting 'connecting new client' twice and saying 'new client connected', creating a false impression when an error (like a timeout) was present.
2018-05-04 13:06:49 -05:00
Yuval Greenfield
6b2883d290 terminiated -> terminated (#78) 2018-05-04 13:06:32 -05: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
2f14cb1a0f Update CI versions (#88)
* Update CI versions

PostgreSQL 9.1 is no longer available on 14.04.

* Add Node 9 to CI
2018-04-06 11:28:03 -05:00
Brian Carlson
4d7734a711 Bump version 2017-08-10 09:01:31 -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 Carlson
c3417e95eb Bump version 2017-08-10 00:21:10 -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 Carlson
a446537377 Bump version 2017-07-14 14:07:19 -05:00
Brian C
40f5126b6e Fix idle client teardown on error (#68)
- Re-add default idleTimeoutMillis = 10000 by default
- Fix idle timeout clearing on shutdown
- Ensure idleTimeoutMillis is used in timeout
2017-07-14 14:07:07 -05:00
Brian C
2421a769cb Update README.md 2017-07-13 22:40:26 -05:00
Brian Carlson
139cbdea16 Bump version 2017-07-13 22:37:45 -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 M. Carlson
0c32c57e0e Bump version 2017-06-18 14:09:54 -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
Brian C
f93385284d Update .travis.yml 2017-06-02 13:00:42 -05:00
Brian C
a51fe56bc1 Update .travis.yml
Drop node@0.10 and node@0.12 from the test matrix.
2017-06-02 09:40:11 -05:00
Amila Welihinda
52c96a4b2e Create LICENSE (#54)
* Create LICENSE

* Update LICENSE
2017-05-29 10:48:58 -05:00
brianc
659a448fab Bump version 2017-04-13 10:50:00 -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
Brian M. Carlson
5918a9e105 Bump version 2017-04-01 18:43:04 -05:00
Lewis J Ellis
0b3d68ef31 Bump generic-pool dep to 2.4.3 (#35) 2017-04-01 11:31:33 -05:00
Raul Ochoa
0f323999fc Access Promise through global (#39)
This matches the proposed way in "bring your own promise".
2017-04-01 11:28:27 -05:00
Shakeel Mohamed
2aed8bf7b3 Add syntax highlighting to code block in README (#42) 2017-03-06 11:47:30 -06:00
Brian Carlson
ab70f57923 Bump version 2016-12-04 17:27:10 -06: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
Brian M. Carlson
fbdfc15b89 Bump version 2016-09-13 21:29:56 -05: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
Brian M. Carlson
cf28f9357f Bump version 2016-08-26 09:11:18 -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
Brian M. Carlson
f2221a4040 Bump version 2016-08-26 09:07:54 -05:00
Brian M. Carlson
afce7ed6e3 Bump version 2016-08-26 09:05:46 -05:00
brianc
9964208fe8 Bump version 2016-08-05 16:23:05 -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
Risto Novik
1d89029ba7 Added missing new keyword to Heroku example. (#21) 2016-07-26 10:18:14 -05:00
Timothy Haley
e2d77719e7 Url parsing example (#19)
* Added URL parsing example

* Typos and cleanup

* Last typo
2016-07-18 15:54:57 -05:00
brianc
8c42c4172b Bump version 2016-07-03 16:17:55 -07: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
ef1b15e13a Update README.md
Add note on "bring your own promise"
2016-06-30 15:22:49 -07:00
brianc
22a76ddd1d Bump version 2016-06-26 22:05:46 -07:00
brianc
d1c70ec9c1 Update documentation 2016-06-26 22:02:49 -07: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
Peter W
ce173f8c28 Fix error event doc in README (#15)
- making error event example code start by acquiring `pool` in
  the same way it is done in the example at the top for `create`
2016-06-26 21:39:36 -07:00
Peter W
d316ef5524 Fix example code for connect event (#14) 2016-06-25 11:21:40 -07:00