Unable to connect to Redis server at random points with `ioredis`
Hello! I noticed for my Expres.js API that at some points in the day it fails to connect to the Redis server or times out, and I believe is happens while the server is completing it's background saving tasks. Is there something I'm doing wrong?
I'm using
ioredis
as the client if that helps any.
The screenshot is of the type of error I was receiving (before I added a connection error handler).Solution:Jump to solution
do you wanna try the new redis template? the one that will let you connect to it over the private network?
23 Replies
Project ID:
4206f054-da69-4f99-a874-b5ad02cc2550
4206f054-da69-4f99-a874-b5ad02cc2550
I'm connecting to the Redis instance with the
REDIS_URL
environment variable so I decided to double-check the docs on connecting to Redis through Railway.
It states that a REDIS_PRIVATE_URL
is available if a service is within the same project, however it doesn't seem like one is exported?
I'm gonna look into connecting via the TCP Proxy wayneither the internal private url or the tcp proxy is applicable for the database plugins
Oh oops
the database plugins are not available on the private network, and they have their own old tcp proxy implementation that is not the same as what the docs are talking about
Are the docs referring to something new then?
yes they are
not applicable here since you are using the old plugins
but as for why you are seeing issues, I have no clue
Solution
do you wanna try the new redis template? the one that will let you connect to it over the private network?
Yeah, I'll try that. I'll make your answer as the solution and then make a new help thread if I still run into any issues, thanks!
It seems to be a TLS issue and I think by upgrading to the new template I could solve the problems I have, ex: https://upstash.com/docs/redis/troubleshooting/econn_reset
Upstash Documentation
Error read ECONNRESET - Upstash Documentation
do you know where to find the new redis template?
@Brody Hmmmm, following "New Service -> Database -> Add Redis" isn't it. I assume it's "New Service -> Template -> Redis," correct?
correct
Awesome, thanks!
Ahhhhhh, they talk about the templates in the launch week https://blog.railway.app/p/launch-01-next-gen-databases, I gotta read the rest of this today then
for sure!
so now those new database v2 templates come with a variable that's named something like
REDIS_PRIVATE_URL
or something, so instead of your service variables referencing the regular redis url variables, just change the reference over to your new redis service and it's private url variableRight, I saw that! That'll be perfect for me, exactly what I needed
then as long as you only ever connect to it over the private network you can go ahead and remove the public tcp proxy it comes with by default to totally close off the possibility of anyone trying connection attempts to it publicly
@Brody So I removed the TCP proxy, and using the private URL in combination with this
ioredis
setting: https://github.com/redis/ioredis/issues/1203#issuecomment-976127676 I should be goodGitHub
Unhandled error event: Error: read ECONNRESET at TCP.onStreamRead ·...
Hi, I am getting below error sometimes. Redis connection gets disconnected sometime. Out of 10 I am facing this issue 2 time. It takes time to reconnect the server and api response time increases f...
friendly reminder, we don't do pings in this server #🛂|readme #5
Gotcha, thanks
sorry about that
but yes, you should be good, as long as you set the reference variables up correctly
I'll have to try later tonight but I'm running into issues connecting via Private Networking 🥲
would you happen to be building with an alpine based docker image?