#websocket server cannot connect to redis

48 messages · Page 1 of 1 (latest)

sour olive
#

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
west wyvernBOT
#

Project ID: 57346011-633f-4c77-851f-83e2a6f54bc0

sour olive
#

57346011-633f-4c77-851f-83e2a6f54bc0

toxic bobcat
#

can you connect to the database with something like dbgate?

sour olive
toxic bobcat
#

okay thats good

#

have you updated the environment variables you use?

sour olive
#

${{Redis.REDIS_URL}}

toxic bobcat
#

show me the client code that connects to redis please

sour olive
#
import { createClient } from "redis";

const redisUrl = process.env.REDIS_URL;

const redisCon = {
  url: redisUrl,
};
sour olive
toxic bobcat
#

and can i see your service variables?

sour olive
#

the redis url was cut off at the bottom. heres a better ss

toxic bobcat
#

these are service variables from the redis service, please show me the variables on your apps service

toxic bobcat
#

what is the raw value of the redis url

sour olive
toxic bobcat
#

if you're using a reference variable, its not sensitive

sour olive
toxic bobcat
#

is that what its set to?

sour olive
#

yea when i edit it, thats what shows up. when i click the eye icon, the actual value shows up

toxic bobcat
#

then it leads me to believe you have incorrectly configured your client

sour olive
#

how can i see if theres any misconfiguration

toxic bobcat
#

consult the documentation for the redis client in use

sour olive
toxic bobcat
#

Q: how can i see if theres any misconfiguration
A: consult the documentation for the the redis client you are using in your code

sour olive
#

the redis client connects fine to the instance

toxic bobcat
#

that does not mean there isnt a misconfiguration

sour olive
candid fossil
#

if you console.log the REDIS_URL, does that match what you expect?

#

wondering if the migration messed up the env variable somehow

sour olive
#

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

candid fossil
#

did you say you can use that url in your local env and it works?

sour olive
#

this issue only started when i was forced to migrate my redis db on railway

candid fossil
#

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

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...

sour olive
#

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

candid fossil
#

Hmm, strange. Ideally you’d connect via your private network