go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
36.76k stars 3.93k forks source link

Automatic database reconnect #5602

Open henning opened 2 years ago

henning commented 2 years ago

Describe the feature

GORM should try to reconnect to a database when connection is lost (e.g. Network error, DB restart)

After the DB restarts, the gorm application usually isnt able to recover and get back to normal operations. That should be solved.

To reproduce the behaviour that I want to avoid - working with Postgres, I get:

Expecation would be that the application reconnects to the DB and continue to work without a restart.

Motivation

GORM applications without DB connection do not work very well.

Related Issues

Multiple issues have been created with that, but all have been closed, but without mentioning a reason or a workaround:

https://github.com/go-gorm/gorm/issues?q=reconnect

There are also some chat messages about it: https://gitter.im/jinzhu/gorm?at=5a59df94ba39a53f1a0e36f2 - but it's not clear to me why gorm doesn't come out of the box with that reconnect behaviour - are there important downsides to configure it by default to reconnect automatically?

I'd be happy to try find a solution for that thing or add some documentation with a workaround if I get some guidance for more experienced gorm developers about how to do it best... maybe there is a reason why it has not been implemented before, or maybe I am overseeing something that makes it not a useful feature.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days

sincerefly commented 1 year ago

I need this feature

borzovplus commented 1 year ago

any updates?

flaxinger commented 1 year ago

I just started googling this topic and landed on this stale issue. Any hints to prebuilt solutions would be of much help (if there are any)

nk915 commented 8 months ago

I need this feature too.

2015WUJI01 commented 3 months ago

Is there any solution now?

Stogas commented 2 months ago

I am unable to replicate this in a Gin API application, i.e. it recovers automatically with a subsequent request.

has this feature been implemented?