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
Project ID:
d0b3dc19-02c9-4290-bf51-904f50b320a7
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 codemight be a dumb question, but do i need to blur out the passkey next to default: when sending screenshots?
you should be using environment variables, your screenshot should not include anything sensitive
i'm trying to use redis with bullmq, if that helps
show me what you have for your service variables please
so what is this imaginary
RAILWAY_KEY
variable?
dont know where you got that from, you want to use REDIS_PRIVATE_URL
that's comin from my .env in my node process, i tried to use REDIS_PRIVATE_URL and that didn't work
what error did you get when you used the proper
REDIS_PRIVATE_URL
variable?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'
}
please use this to download the logs https://bookmarklets.up.railway.app/log-downloader/
that work?
show me your updated code?
can you print that env variable as a sanity check?
yeah it prints
whats your current start command?
npm run start, which just runs my app.js file that contains that screenshot at the top of it
"start": "node app.js"
change that start script to
sleep 3 && node app.js
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?
makes your app wait until the private dns resolver is ready
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'
}
show me your new start script
ah right youd also need to append the
?family=6
to your database urlright, had that on my env version but completely forgot to add that to REDIS_PRIVATE_URL lol
process.env.REDIS_PRIVATE_URL + ?family=6
still nothin sadly
my code: connection = new IORedis(process.env.REDIS_PRIVATE_URL + "?family=6");
youre back to 127.0.0.1 for some reason
yeah, no idea why
express wouldn't have anything to do with it, would it?
will try to reproduce this locally
alright thank you
hmmm i wasn’t able to reproduce this
this was all the code i used
show me your new new code?
this what you're looking for?
sorry just saw your msg
is this the package you are using? https://www.npmjs.com/package/ioredis
yes
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?
yeah sure, is there an email i can share it with? it's private
brody192
Added
did this change anything?
nada
i have no idea why it's forcing the localhost, that's so strange
i can now repo when using bullmq
what do you mean by "repo"?
i think reposistory whenever i hear that lol, must mean somethin else
haha im being lazy, my bad, i meant reproduce
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
got it working on railway like this
i forego the IORedis constructor
the
sleep 3
thing is still needed thoughHey there, still isn't working. Sorry for the delayed response, kinda just forgot to get back to you after reading it
show me your code please, that code 100% works
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'
}
although this isn't the issue, you're back to using railway key, please use the proper variable.
please see this message
ah whoops, mental error
yeah still gettin the same even with the changed env variable
please see this message
yeah still including the sleep 3 as well
"start": "sleep 3 && node app.js",
is that the command railway is actually running though?
how can i check?
in the deploy logs?
build logs, and could be in deploy logs too
i don't see it being ran, no
in either
unless i'm blind
build a deploy logs please https://bookmarklets.up.railway.app/log-downloader/
sure thing
build logs too
is your redis database in the same project
yes
screenshot of the project please
just ran the code i sent above again, no issues
empty array since theres no jobs, but that means the connection worked
do you have private networking enabled?
yes
what does the redis database say its internal domain is?
this is a 2500 line file, why do you have your failed restarts set so high
i didnt really bother to change it since i figured if it kept failing it didn't really matter
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 🤣
this the setting?
set it to never
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
logs please
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
otherwise there's a log
are you running an old version of bullmq?
no, latest one
why is there a DEPRECATION warning?
just noticed they had an update two days ago, i'm on 4.13.2 and most recent is 4.14.2
im on 4.14.0
alright, i'll see if updating does anything
think i found the issue
what's that?
if it involves the worker.js file i just fixed that up
damn, yes, yes it did
great minds think alike, it's working now.
thanks for your help! i'll send you a tip to your buymeacoffee
awe thank you ❤️