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

Borrowed resources never go higher than 1

Open eunito opened this issue 4 years ago • 2 comments

Hi! I'm using the generic-pool and node '.net' in nodeJs to create a socket pool. These are the factory methods I'm using:

create: () => {
     return new Promise((resolve, reject) => {
         const client = net.createConnection(port, ip, () => {
             this.sendCommand(client, `authenticate ${pwd}`); 
         });

         client.on('error', (err) => {
             try {
                 this.sendCommand(client, 'exit');
             } catch (error) {
                 reject(error);
             }

             reject(err);
         });

         client.on('end', () => { 
             console.log('Socket terminated.'); 
         });

         client.on('ready', () => {
             resolve(client);
         });
     })
 },

     destroy: (client) => {
         return new Promise((resolve, reject) => {

         try {
             this.sendCommand(client, 'exit');
             resolve();
         } catch (error) {
             reject(error);
         }
     })
 },
 validate: (client) => {
     return new Promise((resolve) => {
         if (client.destroyed || !client.readable || !client.writable) {
             return resolve(false);
         } else {
             return resolve(true);
         }
     });
 }

and these are the options I'm using:

"poolOptions": {
      "max": 20,
      "min": 5,
      "testOnBorrow": true,
      "idleTimeoutMillis": 30000,
      "acquireTimeoutMillis": 1000,
      "evictionRunIntervalMillis": 14400000,
      "numTestsPerEvictionRun": 3,
    }

When I try to acquire an client from the pool using several requests at once I allway get the feeling that only one of them is being borrowed while the others should also be used if (when acquiring)... I keep getting:

"spareResourceCapacity": 15,
"size": 5,
"available": 4,
"borrowed": 1, // this is the only value that changes from 1 <-> 0
"pending": 0,
"max": 15,
"min": 5

Is it a bug or is there any validation to perform on a new resource acquiring? I simple acquire a resource from the pool await socketPool.acquire(); and then release/destroy it after usage.

eunito avatar Dec 18 '20 11:12 eunito

Any updates on this? I am facing the same issue.

nicmesan2 avatar Feb 08 '23 16:02 nicmesan2

Did you find a fix? I think I have the same problem using generic-pool 3.9.0 and puppeteer.

solitud avatar Feb 01 '24 13:02 solitud