R
Railway•9mo ago
n8levine

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:
Error: getaddrinfo ENOTFOUND postgres.railway.internal

at /app/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:45:11

at processTicksAndRejections (node:internal/process/task_queues:95:5)

at PostgresDriver.acquireConnection (/app/node_modules/.pnpm/[email protected]/node_modules/kysely/dist/cjs/dialect/postgres/postgres-driver.js:21:24)
Error: getaddrinfo ENOTFOUND postgres.railway.internal

at /app/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:45:11

at processTicksAndRejections (node:internal/process/task_queues:95:5)

at PostgresDriver.acquireConnection (/app/node_modules/.pnpm/[email protected]/node_modules/kysely/dist/cjs/dialect/postgres/postgres-driver.js:21:24)
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?
Solution:
do you have a 3 second sleep in your start script?
Jump to solution
13 Replies
Percy
Percy•9mo ago
Project ID: 32bfb0d3-b1b4-4af3-ab7f-efdd0d2968cd
n8levine
n8levineOP•9mo ago
32bfb0d3-b1b4-4af3-ab7f-efdd0d2968cd Also I've experimented with various cron intervals, but that doesn't seem to help much
Brody
Brody•9mo ago
nixpacks or dockerfile based build?
n8levine
n8levineOP•9mo ago
Nixpacks
Solution
Brody
Brody•9mo ago
do you have a 3 second sleep in your start script?
n8levine
n8levineOP•9mo ago
Hm, no not that I know of. Is that something you recommend?
Brody
Brody•9mo ago
yes it's needed because the private network is not available for the first 3 or so seconds
n8levine
n8levineOP•9mo ago
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 😅
Brody
Brody•9mo ago
it is
n8levine
n8levineOP•9mo ago
oh, where?
Brody
Brody•9mo ago
https://docs.railway.app/reference/private-networking#caveats though whoever wrote that got the time very wrong
n8levine
n8levineOP•9mo ago
Got it, yea that's a bit misleading But appreciate the help! gonna go play around with the startup script
Brody
Brody•9mo ago
sounds good!
Want results from more Discord servers?
Add your server