coopernurse/node-pool — pull request #19 by tkrynski (2011-10-11 18:12:05+00:00)
Title: Prevent intermittent, hidden consequences when release is called twice on the same resource

Without this fix, if release is called twice on a resource, it will end up allowing two clients to acquire the resource simultaneously. We spent an entire day trying to figure out why redis was intermittently failing to invoke a callback, until we discovered the multiple releases at 2am... Let's prevent others from suffering the same fate.

BTW, it's rather easy to accidentally release twice:

E.g.,

pool.acquire(function(err, resource) {
resource.use(function(err, data) {
if (err) {
cb(err);
pool.release(resource);
} else {
if (data) {
cb(null, data);
}
}
pool.release(resource);
}
}