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:
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:Jump to 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...10 Replies
Project ID:
d53e252d-5172-48ed-b9af-6468574633d2
It looks like you need to configure a timeout for your workers in production.
⚠️ experimental feature
This seems like a PlanetScale issue.
Then again, planetscalestatus.com doesn't show any incidents.
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
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.
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
@Rhys did u end up solving this?
can you try adding a 5 second delay (sleep) before attempting to connect to the database
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 connectingMain 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