Additional Config Store Cleanup (#16440)
This change addresses a few issues where config stores were not properly closed when an error was encountered on server startup. This could result in leaked database connections when dealing with a database config store.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9283143c3b
Коммит
fe7d9f7643
@@ -611,7 +611,6 @@ func renameChannelCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func searchChannelCmdF(command *cobra.Command, args []string) error {
|
func searchChannelCmdF(command *cobra.Command, args []string) error {
|
||||||
|
|
||||||
a, err := InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to InitDBCommandContextCobra")
|
return errors.Wrap(err, "failed to InitDBCommandContextCobra")
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
|
|
||||||
func InitDBCommandContextCobra(command *cobra.Command) (*app.App, error) {
|
func InitDBCommandContextCobra(command *cobra.Command) (*app.App, error) {
|
||||||
a, err := InitDBCommandContext(getConfigDSN(command, config.GetEnvironment()))
|
a, err := InitDBCommandContext(getConfigDSN(command, config.GetEnvironment()))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Returning an error just prints the usage message, so actually panic
|
// Returning an error just prints the usage message, so actually panic
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ func resetPermissionsCmdF(command *cobra.Command, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer a.Srv().Shutdown()
|
||||||
|
|
||||||
confirmFlag, _ := command.Flags().GetBool("confirm")
|
confirmFlag, _ := command.Flags().GetBool("confirm")
|
||||||
if !confirmFlag {
|
if !confirmFlag {
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ func serverCmdF(command *cobra.Command, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to load configuration")
|
return errors.Wrap(err, "failed to load configuration")
|
||||||
}
|
}
|
||||||
|
defer configStore.Close()
|
||||||
|
|
||||||
return runServer(configStore, usedPlatform, interruptChan)
|
return runServer(configStore, usedPlatform, interruptChan)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ func versionCmdF(command *cobra.Command, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer a.Srv().Shutdown()
|
||||||
|
|
||||||
printVersion(a)
|
printVersion(a)
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,12 @@ func NewDatabaseStore(dsn string) (ds *DatabaseStore, err error) {
|
|||||||
return nil, errors.Wrapf(err, "failed to connect to %s database", driverName)
|
return nil, errors.Wrapf(err, "failed to connect to %s database", driverName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
db.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
ds = &DatabaseStore{
|
ds = &DatabaseStore{
|
||||||
driverName: driverName,
|
driverName: driverName,
|
||||||
originalDsn: dsn,
|
originalDsn: dsn,
|
||||||
@@ -55,7 +61,8 @@ func NewDatabaseStore(dsn string) (ds *DatabaseStore, err error) {
|
|||||||
db: db,
|
db: db,
|
||||||
}
|
}
|
||||||
if err = initializeConfigurationsTable(ds.db); err != nil {
|
if err = initializeConfigurationsTable(ds.db); err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to initialize")
|
err = errors.Wrap(err, "failed to initialize")
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ds, nil
|
return ds, nil
|
||||||
|
|||||||
@@ -54,7 +54,13 @@ func NewStore(dsn string, watch bool, customDefaults *model.Config) (*Store, err
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewStoreFromBacking(backingStore, customDefaults)
|
store, err := NewStoreFromBacking(backingStore, customDefaults)
|
||||||
|
if err != nil {
|
||||||
|
backingStore.Close()
|
||||||
|
return nil, errors.Wrap(err, "failed to create store")
|
||||||
|
}
|
||||||
|
|
||||||
|
return store, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStoreFromBacking(backingStore BackingStore, customDefaults *model.Config) (*Store, error) {
|
func NewStoreFromBacking(backingStore BackingStore, customDefaults *model.Config) (*Store, error) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user