R
Railway•14mo ago
agrattan

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).
No description
Solution:
do you wanna try the new redis template? the one that will let you connect to it over the private network?
Jump to solution
23 Replies
Percy
Percy•14mo ago
Project ID: 4206f054-da69-4f99-a874-b5ad02cc2550
agrattan
agrattan•14mo ago
4206f054-da69-4f99-a874-b5ad02cc2550
agrattan
agrattan•14mo ago
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 way
No description
No description
Brody
Brody•14mo ago
neither the internal private url or the tcp proxy is applicable for the database plugins
agrattan
agrattan•14mo ago
Oh oops
Brody
Brody•14mo ago
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
agrattan
agrattan•14mo ago
Are the docs referring to something new then?
Brody
Brody•14mo ago
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
Brody
Brody•14mo ago
do you wanna try the new redis template? the one that will let you connect to it over the private network?
agrattan
agrattan•14mo ago
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
Brody
Brody•14mo ago
do you know where to find the new redis template?
agrattan
agrattan•14mo ago
@Brody Hmmmm, following "New Service -> Database -> Add Redis" isn't it. I assume it's "New Service -> Template -> Redis," correct?
Brody
Brody•14mo ago
correct
agrattan
agrattan•14mo ago
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
Brody
Brody•14mo ago
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 variable
agrattan
agrattan•14mo ago
Right, I saw that! That'll be perfect for me, exactly what I needed
Brody
Brody•14mo ago
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
agrattan
agrattan•14mo ago
@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 good
GitHub
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...
Brody
Brody•14mo ago
friendly reminder, we don't do pings in this server #🛂|readme #5
agrattan
agrattan•14mo ago
Gotcha, thanks sorry about that
Brody
Brody•14mo ago
but yes, you should be good, as long as you set the reference variables up correctly
agrattan
agrattan•14mo ago
I'll have to try later tonight but I'm running into issues connecting via Private Networking 🥲
No description
Brody
Brody•14mo ago
would you happen to be building with an alpine based docker image?
Want results from more Discord servers?
Add your server