pg-pool
Advanced tools
Comparing version 3.3.0 to 3.4.0
13
index.js
@@ -86,2 +86,3 @@ 'use strict' | ||
this.options.maxUses = this.options.maxUses || Infinity | ||
this.options.allowExitOnIdle = this.options.allowExitOnIdle || false | ||
this.log = this.options.log || function () {} | ||
@@ -140,2 +141,3 @@ this.Client = this.options.Client || Client || require('pg').Client | ||
const client = idleItem.client | ||
client.ref() | ||
const idleListener = idleItem.idleListener | ||
@@ -173,3 +175,3 @@ | ||
// if we don't have to connect a new client, don't do so | ||
if (this._clients.length >= this.options.max || this._idle.length) { | ||
if (this._isFull() || this._idle.length) { | ||
// if we have idle clients schedule a pulse immediately | ||
@@ -329,4 +331,13 @@ if (this._idle.length) { | ||
}, this.options.idleTimeoutMillis) | ||
if (this.options.allowExitOnIdle) { | ||
// allow Node to exit if this is all that's left | ||
tid.unref() | ||
} | ||
} | ||
if (this.options.allowExitOnIdle) { | ||
client.unref() | ||
} | ||
this._idle.push(new IdleItem(client, idleListener, tid)) | ||
@@ -333,0 +344,0 @@ this._pulseQueue() |
{ | ||
"name": "pg-pool", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "Connection pool for node-postgres", | ||
@@ -40,3 +40,3 @@ "main": "index.js", | ||
}, | ||
"gitHead": "d45947938263bec30a1e3252452f04177b785f66" | ||
"gitHead": "f3b0ee4c09cd01e37baf580d72dffc43edcc29f3" | ||
} |
@@ -68,14 +68,2 @@ 'use strict' | ||
describe('calling connect after end', () => { | ||
it('should return an error', function* () { | ||
const pool = new Pool() | ||
const res = yield pool.query('SELECT $1::text as name', ['hi']) | ||
expect(res.rows[0].name).to.equal('hi') | ||
const wait = pool.end() | ||
pool.query('select now()') | ||
yield wait | ||
expect(() => pool.query('select now()')).to.reject() | ||
}) | ||
}) | ||
describe('using an ended pool', () => { | ||
@@ -82,0 +70,0 @@ it('rejects all additional promises', (done) => { |
@@ -7,2 +7,4 @@ 'use strict' | ||
const it = require('mocha').it | ||
const { fork } = require('child_process') | ||
const path = require('path') | ||
@@ -88,2 +90,31 @@ const Pool = require('../') | ||
) | ||
it('unrefs the connections and timeouts so the program can exit when idle when the allowExitOnIdle option is set', function (done) { | ||
const child = fork(path.join(__dirname, 'idle-timeout-exit.js'), [], { | ||
silent: true, | ||
env: { ...process.env, ALLOW_EXIT_ON_IDLE: '1' }, | ||
}) | ||
let result = '' | ||
child.stdout.setEncoding('utf8') | ||
child.stdout.on('data', (chunk) => (result += chunk)) | ||
child.on('error', (err) => done(err)) | ||
child.on('close', () => { | ||
expect(result).to.equal('completed first\ncompleted second\n') | ||
done() | ||
}) | ||
}) | ||
it('keeps old behavior when allowExitOnIdle option is not set', function (done) { | ||
const child = fork(path.join(__dirname, 'idle-timeout-exit.js'), [], { | ||
silent: true, | ||
}) | ||
let result = '' | ||
child.stdout.setEncoding('utf8') | ||
child.stdout.on('data', (chunk) => (result += chunk)) | ||
child.on('error', (err) => done(err)) | ||
child.on('close', () => { | ||
expect(result).to.equal('completed first\ncompleted second\nremoved\n') | ||
done() | ||
}) | ||
}) | ||
}) |
@@ -10,6 +10,5 @@ 'use strict' | ||
describe('verify', () => { | ||
it('verifies a client with a callback', false, (done) => { | ||
it('verifies a client with a callback', (done) => { | ||
const pool = new Pool({ | ||
verify: (client, cb) => { | ||
client.release() | ||
cb(new Error('nope')) | ||
@@ -16,0 +15,0 @@ }, |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
65222
21
1531
2
4