Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Handling connection errors. #29

Open
chainhead opened this issue Sep 13, 2019 · 5 comments
Open

Handling connection errors. #29

chainhead opened this issue Sep 13, 2019 · 5 comments

Comments

@chainhead
Copy link

chainhead commented Sep 13, 2019

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?

@silverbucket
Copy link
Owner

Is redis running?

@chainhead
Copy link
Author

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

@FaridAllegis
Copy link

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

@silverbucket
Copy link
Owner

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
Copy link
Owner

Filed a bug upstream, for reference: coopernurse/node-pool#273

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants