Errors Connecting to Postgres with a Cron Job
Hi, I'm running a couple services on Railway, connected to a Postgres instance using the internal connection, which has been working great. Recently I set up a cron job trying to connect to the same Postgres, and sometimes it works fine, but intermittently it gets this error:
When that happens it hangs the cron run as well, preventing any later ones from running (they say skipped). My regular app runs out of the same codebase with very little different but has no issues connecting. Any ideas what's going wrong here?
13 Replies
Project ID:
32bfb0d3-b1b4-4af3-ab7f-efdd0d2968cd
32bfb0d3-b1b4-4af3-ab7f-efdd0d2968cd
Also I've experimented with various cron intervals, but that doesn't seem to help much
nixpacks or dockerfile based build?
Nixpacks
Solution
do you have a 3 second sleep in your start script?
Hm, no not that I know of. Is that something you recommend?
yes it's needed because the private network is not available for the first 3 or so seconds
ooh interesting. That probably explains it then, it's basically just racing and sometimes is slow enough to wait for the network, other times not
Feel like that should be documented somewhere 😅
it is
oh, where?
https://docs.railway.app/reference/private-networking#caveats
though whoever wrote that got the time very wrong
Got it, yea that's a bit misleading
But appreciate the help! gonna go play around with the startup script
sounds good!