How I lost hours of my life by blindly trusting ChatGPT.
This is a lesson that I have learnt multiple times, but it's failing to stick. Here's what happened:
One of my apps that uses the Heroku Redis server for a particular feature stopped working. After some troubleshooting, I found that an instance of Bull Queue Manager failed to connect to the Redis server. Frenzied googling ensued and I came across an update on Heroku's site announcing that it has moved all its Redis mini plan connections to a TLS protocol.
I'll pause here to explain the problem better:
My Bull Queue Manager instance is not connecting to the Redis server.
The parameters I'm using for Bull's Queue function need to be updated since they only work with insecure connections, but now Heroku is forcing all apps to use secure connections.
The fix looked straightforward: update the code to use TLS protocol. However, my brain wanted to deploy the solution in the most calorie-efficient way possible. So, I copied/pasted my code, the error message and Heroku's documentation in ChatGPT and asked it to troubleshoot the issue and recommend a solution. Within seconds, I had what I was looking for: a ready-made snippet that I could slap in my code and live happily ever after.
Here was the solution: instead of using const redisQueue = new Queue('redis-queue', REDIS_URL); I should use const redisQueue = new Queue('redis-queue', { redis: { url: REDIS_URL, tls: { rejectUnauthorized: false, // Again, disable certificate verification for Heroku Redis } } });
At this point, I remembered that Heroku documentation had different instructions for different versions of the Redis package. This is why I asked ChatGPT if the fix would work. As expected, being an LLM, ChatGPT assumed that I was requesting a new solution and presented me with an updated version of the code. Annoyed, I confirmed my Redis version and used the code snippet suggested earlier.
It was time to test the ChatGPT-generated code. I felt pretty confident about the fix, but I was confronted with a new error: connect ECONNREFUSED 127.0.0.1:6379. This was confusing. I wasn't trying to connect to the local host. My brain was eager to outsource troubleshooting of the issue to ChatGPT, so I copied/pasted the error log in the chat interface and hit send without giving ChatGPT any context.
ChatGPT identified the following reason for the error:
The environment variables aren't set correctly.
This is why the code defaults to the fallback URL. The fallback URL indeed pointed to the local host to allow me to test the code on my laptop.
For the resolution of the error, it asked me to follow these steps:
Check and, if needed, update the environment variables. [done]
Update the fallback Redis URL to the primary URL in case an issue is causing the app to revert to fallback [done]
Check the Heroku add-on status [done]
Running the code after completing the above steps resulted in the same error: connect ECONNREFUSED 127.0.0.1:6379. At this point, I was getting desperate. So, I copy-pasted the entire code in ChatGPT and asked it to find another reason for the error. This time around, ChatGPT noticed something that I had missed earlier: I was using a custom module to spin up another Redis Client. It asked me to ensure the Redis URL in that module was using a TLS connection. It wasn't so I fixed the code. I also searched the project for "127.0.0.1" just to be sure I wasn't missing any other reference to the local host. After completing the check, I ran the code again with a mixture of glee, relief and some anticipation.
Error: connect ECONNREFUSED 127.0.0.1:6379
Darkness began enveloping me. I started questioning my sanity. Was everything I had ever known just a mirage? At this point, I had two options: either to distrust my sight or to distrust ChatGPT. I chose the latter and started reading Bull's documentation like the good old days. It turns out, in the absence of a URL, the new Queue() function defaults to 127.0.0.1:6379. That discovery brought the real issue to light: the syntax for calling the new Queue() function that ChatGPT shared was incorrect.
Instead of:
const redisQueue = new Queue('redis-queue', { redis: { url: REDIS_URL, tls: { rejectUnauthorized: false, } } });
It should be:
redisQueue= new Queue('redis-queue', REDIS_URL, queueOptions);
That worked, ending my turmoil. The only question left was: who should I be angry at for wasting away 3 hours of life, myself or the AI?