Unable to connect to Fly Postgres via node JS application

I’ve set up a node app and a Fly Postgres instance and the latter is attached to the former. However, I’m unable to connect the node app to the postgres instance using the process.env.DATABASE_URL value, which was generated automatically for me by Fly. Here’s the redacted error:

Error: getaddrinfo ENOTFOUND postgres://<db_user>:<db_password>@<app-name>-db.flycast:5432/<db_name>?sslmode=disable
2024-10-03T16:29:29Z app[3d8d313c030708] lhr [info]    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)

What’s especially odd is that I can use fly ssh console to open a shell in the app VM and from there use the nodeJS REPL to connect successfully to the database using the value of process.env.DATABASE_URL. Likewise I can connect via the Fly proxy from my local machine. So I can’t understand why the main application process can’t resolve the URL.

Hm… That is odd. Typically, you would have 2+ Node machines, whereas the one that SSH brings you to is fairly random. Maybe only one of the two has glitchy DNS?

(A fellow user encountered that kind of asymmetry last week in nearby cdg.)


Aside: You can SSH to a specific machine with --select (after fly m start, to make sure they’re all running).

Added lhr

Thanks for the response. I’ve been able to SSH into both my node machines and connect to the database successfully from the nodeJS REPL, but the running app process is still unable to resolve the database domain :thinking:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.