coopernurse / node-pool

Generic resource pooling for node.js
2.37k stars 258 forks source link

resource release not getting called #280

Open aksharj opened 4 years ago

aksharj commented 4 years ago

Hi,

Just an update here, i need to explictly call destroy function to release the resourcse, may be i have configured something incorrectly

Sorry to be posting it here but i am unable to find an answer anywhere else.

I am trying to create a pupeteer pool and the destroy method from the factory is not getting called.

I am able to acquire resource but not able to release and destroy is not called.

here are relevant parts of the code

browser-pool.js

const genericPool = require('generic-pool');
const puppeteer = require('puppeteer');

module.exports = function() {

  const browserParams = process.env.NODE_ENV == 'development' ? {
    headless: false,
    devtools: false,
    executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
  }
  :
  {
    headless: true,
    devtools: false,
    executablePath: 'google-chrome-unstable',
    args: ['--no-sandbox', '--disable-dev-shm-usage']
  };

  const factory = {
    create: function() {
      return puppeteer.launch(browserParams);
    },
    destroy: function(instance) {
      console.log('closing browser');
      instance.close();
    },
    validate: (browserInstance) => {
      console.log(`maxUses is ${maxUses}`);
      return validator(browserInstance)
        .then(valid => Promise.resolve(valid && (maxUses <= 0 || browserInstance.useCount < maxUses)))
    },
  }

  const opts = {
    max: 2
  };

  return genericPool.createPool(factory, opts);
};

processor.js

const pool = require('./browser-pool');

async function performExport(params){
  let client = "";
  const poolInstance = pool();
  const resp = workAround.acquire().then(async function(c){
// do processing
poolInstance.release(c); //***Does not call destroy**
});

I am missing something but not sure what. Any help would be really great. Thanks

rkrier85233 commented 3 years ago

I'm seeing the same thing. I have my max: 10 and min: 0 and after I release all resources I still have available: 1.

Abdillah commented 6 months ago

Yes, I'm observing the same.

Additionally, calling drain and clear doesn't call destroy. Why is that?