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

Borrowed resources never go higher than 1 #285

Open
eunito opened this issue Dec 18, 2020 · 2 comments
Open

Borrowed resources never go higher than 1 #285

eunito opened this issue Dec 18, 2020 · 2 comments

Comments

@eunito
Copy link

eunito commented Dec 18, 2020

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.

@nicmesan2
Copy link

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

@solitud
Copy link

solitud commented Feb 1, 2024

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

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