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

Resource not currently part of this pool #293

Open
189 opened this issue Dec 4, 2021 · 1 comment
Open

Resource not currently part of this pool #293

189 opened this issue Dec 4, 2021 · 1 comment

Comments

@189
Copy link

189 commented Dec 4, 2021

I make 20 request after create connection pool with 10 max connection, but always got “Resource not currently part of this pool”。Here is my all code:

const genericPool = require("generic-pool");

const factory = {
  create: function () {
    console.log("factory create");
    return null;
  },
  destroy: function () {
    console.log("====> factory destroy");
    return true;
  }
};

const pool = genericPool.createPool(factory, {
  max: 10, // maximum size of the pool
  idleTimeoutMillis: 30000,
  min: 2
});

function fetch(idx) {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log(idx, "done");
      resolve();
    }, 1 * 1000);
  });
}

let n = 0;

while (n < 20) {
  ((m) => {
    pool
      .acquire()
      .then((client) => {
        return fetch(m).then(() => {
          console.log(m, "release");
          return pool.release(client);
        });
      })
      .catch(function (err) {
        console.log("err=>", err);
      });
  })(n);
  n++;
}

pool.drain().then(function () {
  pool.clear();
});

image

"generic-pool": "^3.8.2"

Here is online demo

@eliellis
Copy link

eliellis commented Mar 17, 2022

Works fine for me if the pool create function returns something other than null, like an empty object. See here. The implementation compares unique instances internally, and null is not a unique instance when calling release, which is which is why you are seeing this error.

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

2 participants