Skip to content
This repository has been archived by the owner on Dec 30, 2019. It is now read-only.

can only pool max size errors be caught? #95

Open
ouyangxuanyun opened this issue Jan 24, 2018 · 1 comment
Open

can only pool max size errors be caught? #95

ouyangxuanyun opened this issue Jan 24, 2018 · 1 comment

Comments

@ouyangxuanyun
Copy link

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! 
@charmander
Copy link
Collaborator

This might be fixed by #86.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants