redis-connection-pool icon indicating copy to clipboard operation
redis-connection-pool copied to clipboard

Handling connection errors.

Open chainhead opened this issue 4 years ago • 5 comments

What is the correct way to handle error while connecting or otherwise? I am running the code below against a un-started Redis on localhost.

const redisPool = require('redis-connection-pool')
let registryPool
//
function connect(options, callback) {
    registryPool = redisPool('registryPool', options)
    registryPool.on('error', (err) => {
        return callback(err, null)
    })
    registryPool.on('connect', () => {
        return callback(null, registryPool)
    })
}
//
module.exports = {
    connect
}

I get an error as follows:

(node:8566) UnhandledPromiseRejectionWarning: Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)
(node:8566) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:8566) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

And, .catch() or .then() do not seem to be supported.

So, how do we handle errors?

chainhead avatar Sep 13 '19 16:09 chainhead

Is redis running?

silverbucket avatar Sep 17 '19 16:09 silverbucket

No. Therefore, the error is valid. I am not sure how to handle this error.

chainhead avatar Sep 19 '19 03:09 chainhead

This is a great utility and thanks for developing it, however not being able to catch connection errors/exception or having any way to catch promise rejection in case of connection failures cause the node to either exist or stoping responding. I also noticed redisPool takes any port/host without any validation , even if the connection is not stablished , no errors or method on failures are returned hence assuming the connection has successfully stablished, however the unhandled promised Error cause application not responsive.

thanks again

FaridAllegis avatar Sep 26 '19 19:09 FaridAllegis

Thanks both for your feedback. I've identified the error, I just haven't had time to submit a PR. Will do that now.

silverbucket avatar Sep 27 '19 11:09 silverbucket

Filed a bug upstream, for reference: https://github.com/coopernurse/node-pool/issues/273

silverbucket avatar Sep 27 '19 23:09 silverbucket