Socket
Socket
Sign inDemoInstall

pg-pool

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg-pool - npm Package Compare versions

Comparing version 1.7.0 to 1.7.1

28

index.js

@@ -6,2 +6,22 @@ var genericPool = require('generic-pool')

// there is a bug in the generic pool where it will not recreate
// destroyed workers (even if there is waiting work to do) unless
// there is a min specified. Make sure we keep some connections
// SEE: https://github.com/coopernurse/node-pool/pull/186
// SEE: https://github.com/brianc/node-pg-pool/issues/48
// SEE: https://github.com/strongloop/loopback-connector-postgresql/issues/231
function _ensureMinimum () {
var i, diff, waiting
if (this._draining) return
waiting = this._waitingClients.size()
if (this._factory.min > 0) { // we have positive specified minimum
diff = this._factory.min - this._count
} else if (waiting > 0) { // we have no minimum, but we do have work to do
diff = Math.min(waiting, this._factory.max - this._count)
}
for (i = 0; i < diff; i++) {
this._createResource()
}
};
var Pool = module.exports = function (options, Client) {

@@ -21,2 +41,10 @@ if (!(this instanceof Pool)) {

this.pool = new genericPool.Pool(this.options)
// Monkey patch to ensure we always finish our work
// - There is a bug where callbacks go uncalled if min is not set
// - We might still not want a connection to *always* exist
// - but we do want to create up to max connections if we have work
// - still waiting
// This should be safe till the version of pg-pool is upgraded
// SEE: https://github.com/coopernurse/node-pool/pull/186
this.pool._ensureMinimum = _ensureMinimum
this.onCreate = this.options.onCreate

@@ -23,0 +51,0 @@ }

2

package.json
{
"name": "pg-pool",
"version": "1.7.0",
"version": "1.7.1",
"description": "Connection pool for node-postgres",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -197,2 +197,32 @@ var expect = require('expect.js')

describe('pool error handling', function () {
it('Should complete these queries without dying', function (done) {
var pgPool = new Pool()
var pool = pgPool.pool
pool._factory.max = 1
pool._factory.min = null
var errors = 0
var shouldGet = 0
function runErrorQuery () {
shouldGet++
return new Promise(function (resolve, reject) {
pgPool.query("SELECT 'asd'+1 ").then(function (res) {
reject(res) // this should always error
}).catch(function (err) {
errors++
resolve(err)
})
})
}
var ps = []
for (var i = 0; i < 5; i++) {
ps.push(runErrorQuery())
}
Promise.all(ps).then(function () {
expect(shouldGet).to.eql(errors)
done()
})
})
})
process.on('unhandledRejection', function (e) {

@@ -199,0 +229,0 @@ console.error(e.message, e.stack)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc