DB connect kills the process on error #3784
Replies: 2 comments
-
Hey @c-wygoda I think this is a reasonable request. We could attempt to handle connections as you've noted, and then only throw after a certain amount of failed attempts. Have you done this successfully with other packages in the past? Say, a raw ORM or similar? I will add this as a roadmap candidate. For now, you could ensure database availability before you call I'll keep you updated regarding the status of this feature request on our roadmap! |
Beta Was this translation helpful? Give feedback.
-
Here's a draft PR with what I think this should like (sorry for account jumping): #3790 I'm using retries across my projects - or rather have my teams use it - when talking to external resources as a defensive measure against whatever might be flaky - DNS, networking in general, still starting, etc. Usually with an exponential backoff, but I think this is a decent start. Would you point me to where to add tests for this and documentation? I hope to find some time in the next days after vacation to provide those changes as well. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Link to reproduction
No response
Describe the Bug
It is not possible to use the
db.connect
method with retrying on error, as it catches the connection errors and kills the process:IMHO, instead of killing there, the error should be allowed to bubble up and caught and possibly process-killed in Payload's
init
default connection attempt: https://github.com/payloadcms/payload/blob/main/packages/payload/src/payload.ts#L360This would allow to set
disableDBConnect
tofalse
and for example try and retry the DB connection in theonInit
handler.My motivation is to start a dockerized DB in parallel to Payload and just retry until it is available. Using something like wait-for-it.sh always feels like code not handling unready resources very well to me. I might even argue for the default connect attempt in the init method to retry, maybe with an max timeout to allow waiting for starting databases.
To Reproduce
payload.db.connect()
on error in the onInit handler withdisableDBConnect
set to false.Payload Version
2
Adapters and Plugins
db-postgres
Beta Was this translation helpful? Give feedback.
All reactions