node-pg-pool icon indicating copy to clipboard operation
node-pg-pool copied to clipboard

can only pool max size errors be caught?

Open ouyangxuanyun opened this issue 7 years ago • 1 comments

Hi,

It seems that only pool-max-size errors can be caught when using pool.connect() function . following is a test case: pg host is fake data and can not connect to . I thought output should catch 10 ETIMEDOUT errors, but actually it turns out catch only 3 which is pool-max-size, after changing max to 10 all errors can be caught. Is that means pool.connect() can only catch pool-max-size errors ? if so, how to make sure pool.connect() get client successfully or just pending because connections are larger than pool-max-size?

Thanks a lot !

const Pool = require('pg-pool')
// fake host
let config = {
  host: '172.18.0.15',
  port: 5432,
  user: 'postgres',
  password: 'postgres',
  database: 'postgres',
  max: 3,
  min: 1,
  schema: 'public'
};

const pool = new Pool(config)
pool.on('error', (err) => {
  console.error('An idle client has experienced an error', err.stack);
});

const query = () => {
  return pool.connect().then((client) => {
    console.log('get client, then do nothing');
    return 'OK';
  }).catch((err) => {
      console.error('catch an error! ');
      // console.log(err);
    });
};

for(let i = 0; i < 10; i++) {
  query();
}

result:

catch an error! 
catch an error! 
catch an error! 

ouyangxuanyun avatar Jan 24 '18 08:01 ouyangxuanyun

This might be fixed by #86.

charmander avatar Jan 24 '18 08:01 charmander