node-pool
node-pool copied to clipboard
Borrowed resources never go higher than 1
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.
Any updates on this? I am facing the same issue.
Did you find a fix? I think I have the same problem using generic-pool 3.9.0 and puppeteer.