R
Railway13mo ago
ThomasZ

connecting to redis over the private network

Project ID: d0b3dc19-02c9-4290-bf51-904f50b320a7 Hey y'all, having trouble connecting my nodejs app using IORedis to railway's redis instance. Getting this error message: Error: connect ECONNREFUSED 127.0.0.1:6379 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) { errno: -111, code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 6379 } My connection string is formatted like so: connection = new IORedis('redis://default:[email protected]:6379?family=6'); Any help?
102 Replies
Percy
Percy13mo ago
Project ID: d0b3dc19-02c9-4290-bf51-904f50b320a7
Brody
Brody13mo ago
Error: connect ECONNREFUSED 127.0.0.1:6379
127.0.0.1:6379 is the default host:port ioredis will use. please show screenshots of code
ThomasZ
ThomasZOP13mo ago
might be a dumb question, but do i need to blur out the passkey next to default: when sending screenshots?
Brody
Brody13mo ago
you should be using environment variables, your screenshot should not include anything sensitive
ThomasZ
ThomasZOP13mo ago
No description
ThomasZ
ThomasZOP13mo ago
i'm trying to use redis with bullmq, if that helps
Brody
Brody13mo ago
show me what you have for your service variables please
ThomasZ
ThomasZOP13mo ago
No description
Brody
Brody13mo ago
so what is this imaginary RAILWAY_KEY variable? dont know where you got that from, you want to use REDIS_PRIVATE_URL
ThomasZ
ThomasZOP13mo ago
that's comin from my .env in my node process, i tried to use REDIS_PRIVATE_URL and that didn't work
Brody
Brody13mo ago
what error did you get when you used the proper REDIS_PRIVATE_URL variable?
ThomasZ
ThomasZOP13mo ago
give me a sec, gonna redeploy real quick Error: getaddrinfo ENOTFOUND redis.railway.internal at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26) { errno: -3007, code: 'ENOTFOUND', syscall: 'getaddrinfo', hostname: 'redis.railway.internal' }
Brody
Brody13mo ago
please use this to download the logs https://bookmarklets.up.railway.app/log-downloader/
ThomasZ
ThomasZOP13mo ago
that work?
Brody
Brody13mo ago
show me your updated code?
ThomasZ
ThomasZOP13mo ago
No description
Brody
Brody13mo ago
can you print that env variable as a sanity check?
ThomasZ
ThomasZOP13mo ago
yeah it prints
No description
Brody
Brody13mo ago
whats your current start command?
ThomasZ
ThomasZOP13mo ago
npm run start, which just runs my app.js file that contains that screenshot at the top of it "start": "node app.js"
Brody
Brody13mo ago
change that start script to sleep 3 && node app.js
ThomasZ
ThomasZOP13mo ago
yeah that was gonna be my next guess, saw that mentioned a couple times in here, trying it now i'm guessing it gives railway a second to connect right?
Brody
Brody13mo ago
makes your app wait until the private dns resolver is ready
ThomasZ
ThomasZOP13mo ago
still getting Error: getaddrinfo ENOTFOUND redis.railway.internal at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26) { errno: -3007, code: 'ENOTFOUND', syscall: 'getaddrinfo', hostname: 'redis.railway.internal' }
ThomasZ
ThomasZOP13mo ago
No description
Brody
Brody13mo ago
show me your new start script
ThomasZ
ThomasZOP13mo ago
No description
Brody
Brody13mo ago
ah right youd also need to append the ?family=6 to your database url
ThomasZ
ThomasZOP13mo ago
right, had that on my env version but completely forgot to add that to REDIS_PRIVATE_URL lol
Brody
Brody13mo ago
process.env.REDIS_PRIVATE_URL + ?family=6
ThomasZ
ThomasZOP13mo ago
still nothin sadly
No description
ThomasZ
ThomasZOP13mo ago
my code: connection = new IORedis(process.env.REDIS_PRIVATE_URL + "?family=6");
Brody
Brody13mo ago
youre back to 127.0.0.1 for some reason
ThomasZ
ThomasZOP13mo ago
yeah, no idea why express wouldn't have anything to do with it, would it?
Brody
Brody13mo ago
will try to reproduce this locally
ThomasZ
ThomasZOP13mo ago
alright thank you
Brody
Brody13mo ago
hmmm i wasn’t able to reproduce this
No description
Brody
Brody13mo ago
this was all the code i used
import Redis from 'ioredis';

const redis = new Redis(process.env.REDIS_PRIVATE_URL + '?family=6');

const ping = await redis.ping();

console.log(ping);
import Redis from 'ioredis';

const redis = new Redis(process.env.REDIS_PRIVATE_URL + '?family=6');

const ping = await redis.ping();

console.log(ping);
show me your new new code?
ThomasZ
ThomasZOP13mo ago
this what you're looking for?
No description
ThomasZ
ThomasZOP13mo ago
sorry just saw your msg
Brody
Brody13mo ago
is this the package you are using? https://www.npmjs.com/package/ioredis
ThomasZ
ThomasZOP13mo ago
yes
Brody
Brody13mo ago
can you do away with the whole if else thing for now? i dont see how it could be an issue, but i dont have any other ideas right now and if that doesnt do anything, can you share your repo?
ThomasZ
ThomasZOP13mo ago
yeah sure, is there an email i can share it with? it's private
Brody
Brody13mo ago
brody192
ThomasZ
ThomasZOP13mo ago
Added
Brody
Brody13mo ago
did this change anything?
ThomasZ
ThomasZOP13mo ago
nada i have no idea why it's forcing the localhost, that's so strange
Brody
Brody13mo ago
i can now repo when using bullmq
ThomasZ
ThomasZOP13mo ago
what do you mean by "repo"? i think reposistory whenever i hear that lol, must mean somethin else
Brody
Brody13mo ago
haha im being lazy, my bad, i meant reproduce
ThomasZ
ThomasZOP13mo ago
you're good, had me confused for a second bullMQ specifcally says to use IORedis and to pass in a string very similar to what i've got, so why it's forcing localhost when on railway is beyond me
Brody
Brody13mo ago
got it working on railway like this
import { Queue } from "bullmq";

const redisURL = new URL(process.env.REDIS_PRIVATE_URL);

const queue = new Queue("Queue", {
connection: {
family: 0,
host: redisURL.hostname,
port: redisURL.port,
username: redisURL.username,
password: redisURL.password
}
});

console.log(await queue.getJobs());
import { Queue } from "bullmq";

const redisURL = new URL(process.env.REDIS_PRIVATE_URL);

const queue = new Queue("Queue", {
connection: {
family: 0,
host: redisURL.hostname,
port: redisURL.port,
username: redisURL.username,
password: redisURL.password
}
});

console.log(await queue.getJobs());
i forego the IORedis constructor the sleep 3 thing is still needed though
ThomasZ
ThomasZOP13mo ago
Hey there, still isn't working. Sorry for the delayed response, kinda just forgot to get back to you after reading it
Brody
Brody13mo ago
show me your code please, that code 100% works
ThomasZ
ThomasZOP13mo ago
No description
ThomasZ
ThomasZOP13mo ago
Getting: Error: getaddrinfo ENOTFOUND redis.railway.internal at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26) { errno: -3007, code: 'ENOTFOUND', syscall: 'getaddrinfo', hostname: 'redis.railway.internal' }
Brody
Brody13mo ago
although this isn't the issue, you're back to using railway key, please use the proper variable. please see this message
ThomasZ
ThomasZOP13mo ago
ah whoops, mental error yeah still gettin the same even with the changed env variable
Brody
Brody13mo ago
please see this message
ThomasZ
ThomasZOP13mo ago
yeah still including the sleep 3 as well "start": "sleep 3 && node app.js",
Brody
Brody13mo ago
is that the command railway is actually running though?
ThomasZ
ThomasZOP13mo ago
how can i check? in the deploy logs?
Brody
Brody13mo ago
build logs, and could be in deploy logs too
ThomasZ
ThomasZOP13mo ago
i don't see it being ran, no in either unless i'm blind
Brody
Brody13mo ago
ThomasZ
ThomasZOP13mo ago
sure thing
Brody
Brody13mo ago
build logs too
Brody
Brody13mo ago
is your redis database in the same project
ThomasZ
ThomasZOP13mo ago
yes
Brody
Brody13mo ago
screenshot of the project please
ThomasZ
ThomasZOP13mo ago
No description
Brody
Brody13mo ago
just ran the code i sent above again, no issues
No description
Brody
Brody13mo ago
empty array since theres no jobs, but that means the connection worked do you have private networking enabled?
ThomasZ
ThomasZOP13mo ago
yes
Brody
Brody13mo ago
what does the redis database say its internal domain is?
Brody
Brody13mo ago
No description
ThomasZ
ThomasZOP13mo ago
No description
Brody
Brody13mo ago
this is a 2500 line file, why do you have your failed restarts set so high
ThomasZ
ThomasZOP13mo ago
i didnt really bother to change it since i figured if it kept failing it didn't really matter
Brody
Brody13mo ago
thats usage, you pay for usage either way, set it to never and try again its still gonna fail, but at least you wont send me a 2500 line log this time 🤣
ThomasZ
ThomasZOP13mo ago
No description
ThomasZ
ThomasZOP13mo ago
this the setting?
Brody
Brody13mo ago
set it to never
ThomasZ
ThomasZOP13mo ago
only accepts an integer oh, whoops thought you were referring to the input, it was the box above lmao yeah it's still crashin sadly, didn't expect that change to do anything tho
Brody
Brody13mo ago
logs please
ThomasZ
ThomasZOP13mo ago
For some reason I have it set to never yet the process doesn't stop upon an error, I think it's because redis constantly checks for it and doesn't technically throw any sort of fatal error. I believe that's a bullmq setting though, i'll look into that
ThomasZ
ThomasZOP13mo ago
otherwise there's a log
Brody
Brody13mo ago
are you running an old version of bullmq?
ThomasZ
ThomasZOP13mo ago
no, latest one
Brody
Brody13mo ago
why is there a DEPRECATION warning?
ThomasZ
ThomasZOP13mo ago
just noticed they had an update two days ago, i'm on 4.13.2 and most recent is 4.14.2
Brody
Brody13mo ago
im on 4.14.0
ThomasZ
ThomasZOP13mo ago
alright, i'll see if updating does anything
Brody
Brody13mo ago
think i found the issue
ThomasZ
ThomasZOP13mo ago
what's that? if it involves the worker.js file i just fixed that up
Brody
Brody13mo ago
damn, yes, yes it did
ThomasZ
ThomasZOP13mo ago
great minds think alike, it's working now. thanks for your help! i'll send you a tip to your buymeacoffee
Brody
Brody13mo ago
awe thank you ❤️
Want results from more Discord servers?
Add your server