From 1cdfe929b42ddbf306e6cd67e2370e246b9775a2 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Sat, 21 Mar 2026 11:32:11 -0500 Subject: [PATCH] block config updates if one is already in progress --- api.go | 4 ++++ router.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/api.go b/api.go index 5302a36..5a12180 100644 --- a/api.go +++ b/api.go @@ -85,6 +85,10 @@ func (r *Router) handleConfigHTTP(w http.ResponseWriter, req *http.Request) { w.Header().Set("Content-Type", "application/json") w.Write(configJSON) case http.MethodPut: + if r.updatingConfig { + http.Error(w, "Config update in progress.", http.StatusConflict) + return + } var newConfig config.Config err := json.NewDecoder(req.Body).Decode(&newConfig) if err != nil { diff --git a/router.go b/router.go index 79b72a8..e0fbfbf 100644 --- a/router.go +++ b/router.go @@ -38,6 +38,7 @@ type Router struct { apiServer *http.Server apiServerMu sync.Mutex apiServerShutdown context.CancelFunc + updatingConfig bool } func (r *Router) addModule(moduleDecl config.ModuleConfig) error { @@ -122,6 +123,7 @@ func NewRouter(routerConfig config.Config) (*Router, []module.ModuleError, []rou ConfigChange: make(chan config.Config, 1), logger: slog.Default().With("component", "router"), runningConfig: routerConfig, + updatingConfig: false, } router.logger.Debug("creating") @@ -318,6 +320,10 @@ func (r *Router) RunningConfig() config.Config { func (r *Router) UpdateConfig(newConfig config.Config) ([]module.ModuleError, []route.RouteError) { r.runningConfigMu.Lock() defer r.runningConfigMu.Unlock() + r.updatingConfig = true + defer func() { + r.updatingConfig = false + }() oldConfig := r.runningConfig r.logger.Debug("received config update", "oldConfig", oldConfig, "newConfig", newConfig)