Errors Connecting to Postgres with a Cron Job
n8levine
PROOP

2 years ago

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/pg-pool@3.6.1_pg@8.11.3/node_modules/pg-pool/index.js:45:11

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

at PostgresDriver.acquireConnection (/app/node_modules/.pnpm/kysely@0.26.3/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?

Solved

15 Replies

n8levine
PROOP

2 years ago

32bfb0d3-b1b4-4af3-ab7f-efdd0d2968cd


n8levine
PROOP

2 years ago

Also I've experimented with various cron intervals, but that doesn't seem to help much


brody
EMPLOYEE

2 years ago

nixpacks or dockerfile based build?


n8levine
PROOP

2 years ago

Nixpacks


brody
EMPLOYEE

2 years ago

do you have a 3 second sleep in your start script?


Status changed to Solved Railway almost 2 years ago


n8levine
PROOP

2 years ago

Hm, no not that I know of. Is that something you recommend?


brody
EMPLOYEE

2 years ago

yes it's needed because the private network is not available for the first 3 or so seconds


n8levine
PROOP

2 years 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


n8levine
PROOP

2 years ago

Feel like that should be documented somewhere 😅


brody
EMPLOYEE

2 years ago

it is


n8levine
PROOP

2 years ago

oh, where?


brody
EMPLOYEE

2 years ago

though whoever wrote that got the time very wrong


n8levine
PROOP

2 years ago

Got it, yea that's a bit misleading


n8levine
PROOP

2 years ago

But appreciate the help! gonna go play around with the startup script


brody
EMPLOYEE

2 years ago

sounds good!


Loading...