Your Question

I've encountered a situation where I need to accurately detect the connection status of a database using GORM. Additionally, I have an implementation for graceful shutdown with a main context that I pass throughout the application. However, I’ve observed that GORM creates its own context with cancellation inside the OpenDB method. I’m curious about the rationale behind having GORM create its own context rather than allowing clients to provide their own. This would enable me to implement retry logic or manage graceful shutdowns for my service.

Note: Here I'm referring to the first step of initiating DB, where the connection loss could happen even before pass context to the db, with db.WithContext, let me know if PingContext solve for any of the above

The document you expected this should be explained

Under Context section

Expected answer

I would like GORM to provide a mechanism to detect when the database connection is closed, along with support for implementing retry logic in case of unexpected connection losses.

Comment From: batman-gotham99

When I wrote this issue on DB connection loss there wasn't any retry happening on the background, however after updating gorm it started to gracefully reconnect, was it an illusion or there was a new change regarding that?

Comment From: github-actions[bot]

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