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

attempt to release an invalid resource: Error? #128

Closed
robfyfe opened this issue Feb 18, 2016 · 4 comments
Closed

attempt to release an invalid resource: Error? #128

robfyfe opened this issue Feb 18, 2016 · 4 comments
Assignees

Comments

@robfyfe
Copy link

robfyfe commented Feb 18, 2016

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)
@sandfox sandfox self-assigned this Feb 18, 2016
@sandfox
Copy link
Collaborator

sandfox commented Feb 18, 2016

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)

@robfyfe
Copy link
Author

robfyfe commented Feb 18, 2016

Hi, thanks for your response. I am using generic-pool 2.4.0 and have tested on a range of node versions including:

  • v0.10.36
  • v0.12.7
  • v4.3.1
  • v5.6.0

@sandfox
Copy link
Collaborator

sandfox commented Feb 24, 2016

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

I've added a few things to the code you kindly included above incase you are interested to help me debug/understand where this is all going wrong :-)
https://gist.github.com/sandfox/9e7306f4467c8dd1950a

@sandfox
Copy link
Collaborator

sandfox commented Mar 26, 2016

fixed by #135

@sandfox sandfox closed this as completed Mar 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants