R
Railway8mo 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
Percy8mo ago
Project ID: 80d4d55f-409c-4c75-9ab3-61d3cefe2e46
DAN
DAN8mo ago
80d4d55f-409c-4c75-9ab3-61d3cefe2e46
Lelebees
Lelebees8mo ago
What kind of app are you running? Are you using private networking?
DAN
DAN8mo 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
Lelebees8mo 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
jtourkos8mo ago
I've noticed the same thing.
Brody
Brody8mo 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
jtourkos8mo 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
Brody8mo ago
are you using the postgres library in code? not quite asking about the database you have deployed
jtourkos
jtourkos8mo ago
no
Brody
Brody8mo ago
what kind of app do you have
jtourkos
jtourkos8mo 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
Brody8mo ago
are you using a pool? yeah the logging issues really hampers debugging
jtourkos
jtourkos8mo ago
Not explicitly. I use the default sequelize options.
Brody
Brody8mo ago
show the error please
jtourkos
jtourkos8mo ago
I don’t have logs 😊
Brody
Brody8mo ago
haha yeah but I'm sure there's logs from a previous (but same) error right?
jtourkos
jtourkos8mo 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
DAN8mo 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
Brody8mo ago
can you set the pool minimum to 0 and see how that goes?
DAN
DAN8mo ago
pool minimum? Do you mean max number of connections?
Brody
Brody8mo ago
i mean the minimum number of connections, aka pool minimum, set it to zero
DAN
DAN8mo ago
hmm I don't see that anywhere in the options interface
Brody
Brody8mo ago
not being able to set the minimum to zero causes issues when running in a docker environment
DAN
DAN8mo 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
Brody8mo ago
railway does not use k8s the postgres databases have 8gb of ram available, same as your plan allows for
DAN
DAN8mo ago
Thanks for the help!
Brody
Brody8mo 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