diff options
Diffstat (limited to '')
-rw-r--r-- | config.go | 53 |
1 files changed, 24 insertions, 29 deletions
@@ -42,39 +42,34 @@ func load_config(path string) error { return err } decoder := scfg.NewDecoder(bufio.NewReader(config_file)) - if func() error { - config_mutex.Lock() - defer config_mutex.Unlock() - err = decoder.Decode(&config) - if err != nil { - return err - } - config_context, config_context_cancel = context.WithCancel(context.Background()) - - // TLS key loading and TLS config creation - cer, err := tls.LoadX509KeyPair(config.TLS.Cert, config.TLS.Key) - if err != nil { - return err - } - config._tls_config = &tls.Config{ - Certificates: []tls.Certificate{cer}, - MinVersion: tls.VersionTLS13, - } + config_mutex.Lock() + defer config_mutex.Unlock() + err = decoder.Decode(&config) + if err != nil { + return err + } + config_context, config_context_cancel = context.WithCancel(context.Background()) - // Database setup - if config.DB.Type != "postgres" { - return err_unsupported_database_type - } - global_db, err = pgxpool.New(config_context, config.DB.Conn) - // BUG: Context-related leak: cancel context when the config is invalidated - if err != nil { - return err - } + // TLS key loading and TLS config creation + cer, err := tls.LoadX509KeyPair(config.TLS.Cert, config.TLS.Key) + if err != nil { + return err + } + config._tls_config = &tls.Config{ + Certificates: []tls.Certificate{cer}, + MinVersion: tls.VersionTLS13, + } - return nil - }() != nil { + // Database setup + if config.DB.Type != "postgres" { + return err_unsupported_database_type + } + global_db, err = pgxpool.New(config_context, config.DB.Conn) + // BUG: Context-related leak: cancel context when the config is invalidated + if err != nil { return err } + return nil } |