Sunday 13 August 2023

rq worker unable to connect to EC2 through Heroku app (SSL: CERTIFICATE_VERIFY_FAILED)

My Heroku app uses Redis and an rq worker. I recently enabled SSL on my Heroku app via the dashboard, and was met with SSL errors. Initially I was met with the following error when hitting an endpoint that used Redis:

app[redis-cylindrical-86839]: Error accepting a client connection: error:14094418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca

but I resolved that by following advice read on a similar Stack Overflow thread by initializing Redis in-code with ssl_cert_reqs=None. However, I'm still being met with the following error in my rq worker:

app[worker.1]: ERROR:root:Error 1 connecting to ec2-XX-XXX-XX-XXX.compute-1.amazonaws.com:11459. [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1002).

and the worker then crashes. Nothing I've tried thus far has worked (mainly different methods of initializing Redis found on StackOverflow or suggested by Heroku support).

My current initialization code:

from redis import Redis, from_url as redis_from_url
from rq import Queue
from dotenv import load_dotenv

# Setup
load_dotenv()

redis_url = os.getenv('REDIS_URL')
if redis_url:
    parsed_redis_url = urlparse(redis_url)
    redis =  Redis(host=parsed_redis_url.hostname, port=parsed_redis_url.port, password=parsed_redis_url.password, ssl=True, ssl_cert_reqs=None)
else:
    # for local development
    redis = Redis()

Any insight as to what's going on, or better yet how to fix my RQ worker would be greatly appreciated. Also I understand there are similar threads to this on StackOverflow, but none of them mention the issue as it pertains to RQ workers, and none of the solutions have worked for me.



from rq worker unable to connect to EC2 through Heroku app (SSL: CERTIFICATE_VERIFY_FAILED)

No comments:

Post a Comment