aboutsummaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'config.go')
-rw-r--r--config.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/config.go b/config.go
index 591bcd9..e7d6aa4 100644
--- a/config.go
+++ b/config.go
@@ -22,14 +22,16 @@ var config struct {
Conn string `scfg:"conn"`
} `scfg:"db"`
MX struct {
- Net string `scfg:"net"`
+ Net string `scfg:"net"`
Addr string `scfg:"addr"`
} `scfg:"mx"`
_tls_config *tls.Config
}
var (
- config_mutex sync.RWMutex // covers things like the database too
- global_db *pgxpool.Pool // only call Close() after replacing this global variable
+ config_mutex sync.RWMutex // covers things like the database too
+ config_context context.Context
+ config_context_cancel context.CancelFunc
+ global_db *pgxpool.Pool // only call Close() after replacing this global variable
)
// load_config loads the configuration file and sets up global things according
@@ -47,6 +49,7 @@ func load_config(path string) error {
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)
@@ -62,7 +65,7 @@ func load_config(path string) error {
if config.DB.Type != "postgres" {
return err_unsupported_database_type
}
- global_db, err = pgxpool.New(context.Background(), config.DB.Conn)
+ 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
@@ -77,7 +80,7 @@ func load_config(path string) error {
// config_fetch_one fetches one value from the configuration.
//
-// Consequtive calls do not guarantee a consistent snapshot of the
+// Consecutive calls do not guarantee a consistent snapshot of the
// configuration. Use config_consistent_run in these cases.
func config_fetch_one[T any](x *T) T {
config_mutex.RLock()