You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am trying to make use of the validateAsync function. I am having trouble so I wrote a small test to show the behaviour I'm seeing. The test behaves as expected if I comment out the validateAsync function and use the synchronous option. However, using the validateAsync function generates the error below the code and subsequently creates a new connection for the third unit of work, rather than reusing the existing one. Furthermore, if I change the max size to 1, rather than 2, then the third unit of work never completes as it cannot acquire a resource to perform the work after the second one has thown the error.
Am I doing anything wrong in the config here? Thanks for your help.
var Pool = require('generic-pool').Pool;
var pool = new Pool(
{
name: 'test-resource-pool',
create: function (callback) {
console.log('### creating resource');
callback(null, {testResource: 'test'});
},
destroy: function (resource) {
console.log('### destroying resource ', resource);
},
// USING validate rather than validateAsync seems to work OK
// validate: function (resource) {
// console.log('synchronous validation', resource);
// return true;
// },
validateAsync: function (resource, callback) {
console.log('### asynchronous validation:', resource);
callback(true);
},
max: 2,
min: 0,
reapIntervalMillis: 5000,
idleTimeoutMillis: 5000,
log: true
});
function executeUnitOfWork(someWork, callback) {
pool.acquire(function (error, resource) {
if (error) {
log.error('### Could not acquire resource from the pool', error);
callback(error);
} else {
console.log('### performing work: ' + someWork);
pool.release(resource);
callback(null, {testData: resource.testResource});
}
});
}
executeUnitOfWork("should create a new resource", function (error, results) {
console.log('### results: ', results);
});
executeUnitOfWork("should re-use an existing resource", function (error, results) {
console.log('### results: ', results);
});
executeUnitOfWork("should re-use an existing resource again", function (error, results) {
console.log('### results: ', results);
});
ERROR pool test-resource-pool - attempt to release an invalid resource: Error
at Pool.release (/home/dev/projects/diary-notes_node/node_modules/generic-pool/lib/generic-pool.js:415:61)
at /home/dev/projects/diary-notes_node/src/main/database/test-pool.js:42:18
at /home/dev/projects/diary-notes_node/node_modules/generic-pool/lib/generic-pool.js:287:13
at Object.Pool.validateAsync (/home/dev/projects/diary-notes_node/src/main/database/test-pool.js:25:13)
at /home/dev/projects/diary-notes_node/node_modules/generic-pool/lib/generic-pool.js:280:23
at next (/home/dev/projects/diary-notes_node/node_modules/generic-pool/lib/generic-pool.js:68:7)
at doWhileAsync (/home/dev/projects/diary-notes_node/node_modules/generic-pool/lib/generic-pool.js:73:3)
at Pool.dispense [as _dispense] (/home/dev/projects/diary-notes_node/node_modules/generic-pool/lib/generic-pool.js:274:7)
at Pool.acquire (/home/dev/projects/diary-notes_node/node_modules/generic-pool/lib/generic-pool.js:387:8)
at executeUnitOfWork (/home/dev/projects/diary-notes_node/src/main/database/test-pool.js:36:10)
The text was updated successfully, but these errors were encountered:
thanks for raising this, quick question, what version of node/generic-pool and platform are you running on (although this probably isn't tied to node version/platform just want to play it safe)
Just to update on my progress with this...
There is very definitely some shortcomings with the asyncValidation behaviour. I've got a mess of stuff on my machine I'm using to debug it all. I'll try and add the useful bits of it to this ticket soon.
The very short answers probably lie in #131 and #132
Hi, I am trying to make use of the validateAsync function. I am having trouble so I wrote a small test to show the behaviour I'm seeing. The test behaves as expected if I comment out the validateAsync function and use the synchronous option. However, using the validateAsync function generates the error below the code and subsequently creates a new connection for the third unit of work, rather than reusing the existing one. Furthermore, if I change the max size to 1, rather than 2, then the third unit of work never completes as it cannot acquire a resource to perform the work after the second one has thown the error.
Am I doing anything wrong in the config here? Thanks for your help.
The text was updated successfully, but these errors were encountered: