R
Railway11mo ago
Callum

Prisma not connecting to DB once deployed

Hey, I have an app and db within a project. The app builds and runs fine on my machine, using the DATABASE_URL provided by railway no problem. Once I deploy to railway, the build works fine but I get a prisma error: PrismaClientInitializationError: Invalid prisma.game.findMany() invocation: Can't reach database server at containers-us-west-95.railway.app:6659 Please make sure your database server is running at containers-us-west-95.railway.app:6659. at Hr.handleRequestError (/app/node_modules/.pnpm/@prisma+client@5.1.0_prisma@5.1.0/node_modules/@prisma/client/runtime/library.js:122:7272) at Hr.handleAndLogRequestError (/app/node_modules/.pnpm/@prisma+client@5.1.0_prisma@5.1.0/node_modules/@prisma/client/runtime/library.js:122:6388) at Hr.request (/app/node_modules/.pnpm/@prisma+client@5.1.0_prisma@5.1.0/node_modules/@prisma/client/runtime/library.js:122:6108) at async l (/app/node_modules/.pnpm/@prisma+client@5.1.0_prisma@5.1.0/node_modules/@prisma/client/runtime/library.js:126:10298) { clientVersion: '5.1.0', errorCode: undefined } Like I say its running fine as I can connect to it locally (and from another app in the project). Any help would be appreciated.
12 Replies
Percy
Percy11mo ago
Project ID: b16fcfcf-a291-4b1b-b5bb-5bc5ef66af6b
Callum
Callum11mo ago
b16fcfcf-a291-4b1b-b5bb-5bc5ef66af6b I have tested deploying the same app to Render, and it works fine there, so as far as I can see this is a railway issue
Brody
Brody11mo ago
word of warning, that doesn't always mean it's a railway issue, but this time it could be, do you happen to have private networking turned on?
Callum
Callum11mo ago
I believe so, I think it is on by default for each service. I have generated a domain for both service as well As an update I've tried adding a dockerfile for the build but I am running into the same issue. The postgres database is also logging some information, which I am assuming is related but that might be wrong: 2023-08-03 08:33:24.100 UTC [45359] LOG: could not receive data from client: Connection reset by peer 2023-08-03 08:34:34.937 UTC [45365] LOG: could not receive data from client: Connection reset by peer Again, its really strange as I have no trouble connecting to the db from the other project or from my local machine
Ray
Ray11mo ago
Hm, can you try increasing Prisma’s connection timeout? This suggests that Prisma is closing the connection early
Callum
Callum11mo ago
Sure, just checking the docs, it looks like I do this by adding some parameters to the connection URL, is that right? https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/connection-pool
Prisma
Connection pool
Prisma's query engine creates a connection pool to store and manage database connections.
Callum
Callum11mo ago
I set the pool_timeout to 0 and its the same problem. So strange!
Ray
Ray11mo ago
Odd. Exact same errors in your latest deploy?
Callum
Callum11mo ago
Yes, looks the same:
Brody
Brody11mo ago
can you try disabling private networking
Callum
Callum11mo ago
That seems to have done it! It is no longer crashing 👍 Strange that the other service was working Is there an alternative way I should communicate with the database other than the URL if the database is in the same project? It would make sense to utilise private network if its available, but I thought it was just for services
Brody
Brody11mo ago
private networking is just for services at the moment, in the future databases will also be a service + volume, then you will be able to connect to them via the private network but there's some current caveats with private networking, like DNS resolution takes 2 seconds to start working when private networking is enabled