R
Railway13mo ago
DAN

App periodically loses connection to postgres

Every few days my web app running in production loses access to the postgres DB I have also deployed via Railway. I see a "connection timeout" error from the client logs, and nothing gets logged to the server according to the Railway observability tab. The only way I have been able to fix it is triggering a re-deployment which presumably rolls the Kubernetes pods. Any ideas?
28 Replies
Percy
Percy13mo ago
Project ID: 80d4d55f-409c-4c75-9ab3-61d3cefe2e46
DAN
DANOP13mo ago
80d4d55f-409c-4c75-9ab3-61d3cefe2e46
Lelebees
Lelebees13mo ago
What kind of app are you running? Are you using private networking?
DAN
DANOP13mo ago
It's a bun app running JS on server and client. Using the postgres library (https://github.com/porsager/postgres) to connect to the DB. Not doing anything special with networking that I know of
Lelebees
Lelebees13mo ago
Okay, bummer. Unfortunately I can't provide much help, but while you wait on people that can help, could you post the error you're receiving? Those are usually very valuable pieces of info :)
jtourkos
jtourkos13mo ago
I've noticed the same thing.
Brody
Brody13mo ago
dan, are you using a pooled connection? @jtourkos - if you arent using bun or the postgres library, please open your own help thread
jtourkos
jtourkos13mo ago
Sure, yes 👍 (I am not using bun. My app's a nodejs. Posted here cause I also use a postgres on Railway and didn't want to create dublicate. I'll open a new one if the issue remains or the solution to this one does cover my case as well).
Brody
Brody13mo ago
are you using the postgres library in code? not quite asking about the database you have deployed
jtourkos
jtourkos13mo ago
no
Brody
Brody13mo ago
what kind of app do you have
jtourkos
jtourkos13mo ago
nodejs with pg and sequelize But sorry, I didn't mean to highjack the issue here 😊 And I cannot confirm that I keep having this issue till the logs are back.
Brody
Brody13mo ago
are you using a pool? yeah the logging issues really hampers debugging
jtourkos
jtourkos13mo ago
Not explicitly. I use the default sequelize options.
Brody
Brody13mo ago
show the error please
jtourkos
jtourkos13mo ago
I don’t have logs 😊
Brody
Brody13mo ago
haha yeah but I'm sure there's logs from a previous (but same) error right?
jtourkos
jtourkos13mo ago
Need to check but I left office now. Let’s see how the logging resolution goes and when I’ll go back to my machine I’ll search and post here if I find anything
DAN
DANOP13mo ago
@Brody Sorry just seeing this. Yes I believe I am using pooled connections, which is the default behavior in the postgres library. Do you think I need to set a timeout option like idle_timeout here? https://github.com/porsager/postgres#connection-timeout
Brody
Brody13mo ago
can you set the pool minimum to 0 and see how that goes?
DAN
DANOP13mo ago
pool minimum? Do you mean max number of connections?
Brody
Brody13mo ago
i mean the minimum number of connections, aka pool minimum, set it to zero
DAN
DANOP13mo ago
hmm I don't see that anywhere in the options interface
Brody
Brody13mo ago
not being able to set the minimum to zero causes issues when running in a docker environment
DAN
DANOP13mo ago
I'm gonna try setting idle_timeout, I wonder if the max connections (default 10) is getting reached and the railway pods are running out of memory
Brody
Brody13mo ago
railway does not use k8s the postgres databases have 8gb of ram available, same as your plan allows for
DAN
DANOP13mo ago
Thanks for the help!
Brody
Brody13mo ago
but yeah this is just a config issue, not so much an issue with railway, not closing the connections properly, leaving stale connections open without marking them as closed, etc etc
Want results from more Discord servers?
Add your server