R
Railway•4mo ago
cucaracha

websocket server cannot connect to redis

ive a websocket server and a redis server hosted on railway. after the migration, my ws server can no longer connect to my redis server. ive tried both the redis url and redis private url but i get the same error:
node:internal/process/promises:288

triggerUncaughtException(err, true /* fromPromise */);

^

ConnectionTimeoutError: Connection timeout

at Socket.<anonymous> (/app/node_modules/@redis/client/dist/lib/client/socket.js:177:124)

at Object.onceWrapper (node:events:631:28)

at Socket.emit (node:events:517:28)

at Socket._onTimeout (node:net:598:8)

at listOnTimeout (node:internal/timers:569:17)

at process.processTimers (node:internal/timers:512:7)

Emitted 'error' event on Commander instance at:

at RedisSocket.<anonymous> (/app/node_modules/@redis/client/dist/lib/client/index.js:412:14)

at RedisSocket.emit (node:events:517:28)

at RedisSocket._RedisSocket_connect (/app/node_modules/@redis/client/dist/lib/client/socket.js:166:18)

at processTicksAndRejections (node:internal/process/task_queues:95:5)

at runNextTicks (node:internal/process/task_queues:64:3)

at listOnTimeout (node:internal/timers:538:9)

at process.processTimers (node:internal/timers:512:7)

at async Commander.connect (/app/node_modules/@redis/client/dist/lib/client/index.js:185:9)

Node.js v18.19.1
node:internal/process/promises:288

triggerUncaughtException(err, true /* fromPromise */);

^

ConnectionTimeoutError: Connection timeout

at Socket.<anonymous> (/app/node_modules/@redis/client/dist/lib/client/socket.js:177:124)

at Object.onceWrapper (node:events:631:28)

at Socket.emit (node:events:517:28)

at Socket._onTimeout (node:net:598:8)

at listOnTimeout (node:internal/timers:569:17)

at process.processTimers (node:internal/timers:512:7)

Emitted 'error' event on Commander instance at:

at RedisSocket.<anonymous> (/app/node_modules/@redis/client/dist/lib/client/index.js:412:14)

at RedisSocket.emit (node:events:517:28)

at RedisSocket._RedisSocket_connect (/app/node_modules/@redis/client/dist/lib/client/socket.js:166:18)

at processTicksAndRejections (node:internal/process/task_queues:95:5)

at runNextTicks (node:internal/process/task_queues:64:3)

at listOnTimeout (node:internal/timers:538:9)

at process.processTimers (node:internal/timers:512:7)

at async Commander.connect (/app/node_modules/@redis/client/dist/lib/client/index.js:185:9)

Node.js v18.19.1
36 Replies
Percy
Percy•4mo ago
Project ID: 57346011-633f-4c77-851f-83e2a6f54bc0
cucaracha
cucaracha•4mo ago
57346011-633f-4c77-851f-83e2a6f54bc0
Brody
Brody•4mo ago
can you connect to the database with something like dbgate?
cucaracha
cucaracha•4mo ago
ive tried connecting from local host with the redis url and it works fine
Brody
Brody•4mo ago
okay thats good have you updated the environment variables you use?
cucaracha
cucaracha•4mo ago
yes. i went into my ws server environment variables and added the redis url as a reference variable ${{Redis.REDIS_URL}}
Brody
Brody•4mo ago
show me the client code that connects to redis please
cucaracha
cucaracha•4mo ago
import { createClient } from "redis";

const redisUrl = process.env.REDIS_URL;

const redisCon = {
url: redisUrl,
};
import { createClient } from "redis";

const redisUrl = process.env.REDIS_URL;

const redisCon = {
url: redisUrl,
};
if i run the ws server locally with this exact code with the REDIS_URL set to the one found in railway redis variables, it works fine
Brody
Brody•4mo ago
and can i see your service variables?
cucaracha
cucaracha•4mo ago
do you just mean these?
No description
cucaracha
cucaracha•4mo ago
the redis url was cut off at the bottom. heres a better ss
No description
Brody
Brody•4mo ago
these are service variables from the redis service, please show me the variables on your apps service
cucaracha
cucaracha•4mo ago
No description
Brody
Brody•4mo ago
what is the raw value of the redis url
cucaracha
cucaracha•4mo ago
isnt that sensitive? can i post it here?
Brody
Brody•4mo ago
if you're using a reference variable, its not sensitive
cucaracha
cucaracha•4mo ago
oh do you mean just ${{Redis.REDIS_URL}}?
Brody
Brody•4mo ago
is that what its set to?
cucaracha
cucaracha•4mo ago
yea when i edit it, thats what shows up. when i click the eye icon, the actual value shows up
Brody
Brody•4mo ago
then it leads me to believe you have incorrectly configured your client
cucaracha
cucaracha•4mo ago
it was all working before i was forced to migrate how can i see if theres any misconfiguration
Brody
Brody•4mo ago
consult the documentation for the redis client in use
cucaracha
cucaracha•4mo ago
sorry not sure what u mean by this
Brody
Brody•4mo ago
Q: how can i see if theres any misconfiguration A: consult the documentation for the the redis client you are using in your code
cucaracha
cucaracha•4mo ago
right but if i run that same code on localhost it works fine the redis client connects fine to the instance
Brody
Brody•4mo ago
that does not mean there isnt a misconfiguration
cucaracha
cucaracha•4mo ago
this also happened directly after i was forced to migrate so im not sure it can be a misconfiguration of the redis client
Brody
Brody•4mo ago
^
macwilko
macwilko•4mo ago
if you console.log the REDIS_URL, does that match what you expect? wondering if the migration messed up the env variable somehow
cucaracha
cucaracha•4mo ago
yes its the exact same url i dont see any configuration issues that it could be. ive also tried updating to the latest version of the redis package and looked at the documentation and its the exact same way its been to connect to a redis instance as when i set it up
macwilko
macwilko•4mo ago
did you say you can use that url in your local env and it works?
cucaracha
cucaracha•4mo ago
exactly this issue only started when i was forced to migrate my redis db on railway
macwilko
macwilko•4mo ago
I think Brody will know better 😅 but at least some reading I did here https://github.com/redis/node-redis/issues/2550 it seems like alot of people experienced some connection issues due to the Redis version. I’m not sure but maybe the package you’re using needs updating?
GitHub
ConnectionTimeoutError: Connection timeout · Issue #2550 · redis/no...
Description Code snippet for connecting the redis is below. this.client = redis.createClient({ socket: { host: redisHost, port: REDISPORT}, }); this.client.connect(); this.client.on("error&quo...
cucaracha
cucaracha•4mo ago
tried updating the package to latest it didnt work also tried increasing the connection timeout limit from 5seconds to 15seconds oh wait nvm i think increasing the connection timeout limit fixed it nope. looks like disabling private network on my redis instance fixedi t no idea why that would do it
macwilko
macwilko•4mo ago
Hmm, strange. Ideally you’d connect via your private network
Brody
Brody•4mo ago
turn private networking back on and then try adding a 3 second sleep to your start command