Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to properly fail factory.create ? #273

Open
silverbucket opened this issue Sep 27, 2019 · 3 comments
Open

How to properly fail factory.create ? #273

silverbucket opened this issue Sep 27, 2019 · 3 comments

Comments

@silverbucket
Copy link

silverbucket commented Sep 27, 2019

From the documentation it seems that you should not handle exceptions during .createPool() but instead during .aquire(). However if the factory.create() function fails, it continues to retry. I've tried both throwing an exception and rejecting the promise and I'm unable to get any controlled failure path from the operation.

const genericPool = require('generic-pool');
const pool = genericPool.createPool({
  create: () => {
    console.log('create called');
    return new Promise((resolve, reject) => {
      console.log('rejecting promise');
      throw new Error('connection problem');
      //reject('connection problem');
    });
  },
  destroy: () => {
    return new Promise((resolve, reject) => { resolve(); });
  }
}, { max: 2 });

console.log("acquire");
pool.acquire().then((client) => {
  console.log("success");
}, (err) => {
  console.log("controlled failure 1");
}).catch((err) => {
  console.log("controlled failure 2");
});

In the above example, aquire is never reached, and I get an endless loop of 'create called' and 'rejecting promise'. The behaviour is the same if I reject or throw.

...
create called
rejecting promise
create called
rejecting promise
create called
rejecting promise
create called
rejecting promise
^C

How can I reliably handle, for example, connection errors to a database, if the user provides incorrect config? Currently either I get a timeout unhandled exception from the DB library, or a hang/endless loop.

@martin-randall-tanium
Copy link

Potential fix and workaround: #221

@silverbucket
Copy link
Author

@Kikobeats @sandfox any update on this issue? It continues to be a source of debugging trouble, with any connection error silently causing an endless loop.

@alanwu4321
Copy link

Can we use this to prevent the issue #175 (comment)

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

No branches or pull requests

3 participants