R
Railway2y ago
Rhys

Intermittent failing to connect to Planetscale

Project id: d53e252d-5172-48ed-b9af-6468574633d2 So this may not be railway related however this is only occurring in my production deployment on Railway so I figured I'd start here The error specifically is:
prisma:error
Invalid `prisma.server.update()` invocation:
Can't reach database server at `us-east.connect.psdb.cloud`:`3306`
Please make sure your database server is running at `us-east.connect.psdb.cloud`:`3306`.
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
prisma:error
Invalid `prisma.server.update()` invocation:
Can't reach database server at `us-east.connect.psdb.cloud`:`3306`
Please make sure your database server is running at `us-east.connect.psdb.cloud`:`3306`.
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
This occurs roughly half the time I deploy it, if I remove the deployment and then redeploy the problem generally goes away Relevant source code: https://github.com/AnswerOverflow/AnswerOverflow/blob/release/apps/discord-bot/src/listeners/parity/guild-parity.ts It's a somewhat high load on start but I tried delaying the operations by about a minute after startup, and making the operations run sequentially but neither helped This issue may be related to: https://discord.com/channels/713503345364697088/1026469676940787753 I'm slightly confused by this issue because everything seems like it should be working correctly but it fails to connect intermittently
GitHub
AnswerOverflow/guild-parity.ts at release · AnswerOverflow/AnswerOv...
Indexing Discord Help Channel Questions into Google - AnswerOverflow/guild-parity.ts at release · AnswerOverflow/AnswerOverflow
Solution:
Yeah I did, it was a few different things: 1. I added ?ssl={"rejectUnauthorized":true}&connect_timeout=60&connection_limit=100&pool_timeout=60 to my connection string 2. I made sure to batch my writes to my database 3. I added a delay for a few seconds after start up before connecting...
Jump to solution
10 Replies
Percy
Percy2y ago
Project ID: d53e252d-5172-48ed-b9af-6468574633d2
Percy
Percy2y ago
It looks like you need to configure a timeout for your workers in production.
⚠️ experimental feature
root
root2y ago
This seems like a PlanetScale issue. Then again, planetscalestatus.com doesn't show any incidents.
Rhys
RhysOP2y ago
It's pretty consistently only in my production railway environment, if I run the production env locally using Railway shell it doesn't give me any of the same errors Slightly hard to debug also since it only occurs intermittently, it also doesn't appear in my staging environment
root
root2y ago
That's really weird. I'm afraid I don't know what's going on, since I've never tried to connect to PlanetScale from Railway and PlanetScale seems to be working fine. My apologies.
Rhys
RhysOP2y ago
Yeah it's a bit strange, no worries 😅 - Another interesting thing is it appears to be able to connect after it continues running for a bit - just left it running and it seemed to sort itself out I'll try bumping the delay before it starts writing to the DB, not a great solution but may work as a stopgap
Tonya
Tonya13mo ago
@Rhys did u end up solving this?
Brody
Brody13mo ago
can you try adding a 5 second delay (sleep) before attempting to connect to the database
Solution
Rhys
Rhys13mo ago
Yeah I did, it was a few different things: 1. I added ?ssl={"rejectUnauthorized":true}&connect_timeout=60&connection_limit=100&pool_timeout=60 to my connection string 2. I made sure to batch my writes to my database 3. I added a delay for a few seconds after start up before connecting
Rhys
RhysOP13mo ago
Main thing was increasing pool size and timeout and batching writes - I think I had a bunch of writes firing off at the same time which overwhelmed my db never ran into it during local testing since the scale wasn't the same
Want results from more Discord servers?
Add your server