fix: close metadb on shutdown (#3277)

Fixes https://github.com/project-zot/helm-charts/issues/70

Signed-off-by: Ramkumar Chinchani <rchincha.dev@gmail.com>
This commit is contained in:
Ramkumar Chinchani
2025-07-29 09:27:26 -07:00
committed by GitHub
parent 966d4584ba
commit b2a5afc5c8
7 changed files with 41 additions and 0 deletions
+6
View File
@@ -455,12 +455,18 @@ func (c *Controller) LoadNewConfig(newConfig *config.Config) {
}
func (c *Controller) Shutdown() {
// stop all background tasks
c.StopBackgroundTasks()
if c.Server != nil {
ctx := context.Background()
_ = c.Server.Shutdown(ctx)
}
// close metadb
if c.MetaDB != nil {
c.MetaDB.Close()
}
}
// Will stop scheduler and wait for all tasks to finish their work.
+7
View File
@@ -2102,3 +2102,10 @@ func resetBucket(transaction *bbolt.Tx, bucketName string) error {
return err
}
func (bdw *BoltDB) Close() error {
err := bdw.DB.Close()
bdw.DB = nil
return err
}
+4
View File
@@ -2274,3 +2274,7 @@ func (dwr *DynamoDB) getDBVersion() (string, error) {
return version, nil
}
func (dwr *DynamoDB) Close() error {
return nil
}
+4
View File
@@ -147,3 +147,7 @@ func toStringIfOk(cacheDriverConfig map[string]interface{},
return str, true
}
func Close(metadb mTypes.MetaDB) error {
return metadb.Close()
}
+7
View File
@@ -2321,3 +2321,10 @@ func unmarshalProtoRepoBlobs(repo string, repoBlobsBytes []byte) (*proto_go.Repo
func join(xs ...string) string {
return strings.Join(xs, ":")
}
func (rc *RedisDB) Close() error {
err := rc.Client.Close()
rc.Client = nil
return err
}
+3
View File
@@ -156,6 +156,9 @@ type MetaDB interface { //nolint:interfacebloat
ImageTrustStore() ImageTrustStore
SetImageTrustStore(imgTrustStore ImageTrustStore)
// Close will close the db
Close() error
}
type UserDB interface { //nolint:interfacebloat
+10
View File
@@ -103,6 +103,8 @@ type MetaDBMock struct {
GetAllRepoNamesFn func() ([]string, error)
ResetDBFn func() error
CloseFn func() error
}
func (sdm MetaDBMock) DeleteRepoMeta(repo string) error {
@@ -461,3 +463,11 @@ func (sdm MetaDBMock) ResetRepoReferences(repo string) error {
return nil
}
func (sdm MetaDBMock) Close() error {
if sdm.CloseFn != nil {
return sdm.CloseFn()
}
return nil
}