From 7ade25d2276abcb01ad6307b41f9b7d6fd44fae8 Mon Sep 17 00:00:00 2001
From: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri, 30 Sep 2022 15:33:29 +0300
Subject: [PATCH] websvc: imp restart

---
 internal/next/websvc/http.go | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/internal/next/websvc/http.go b/internal/next/websvc/http.go
index b00a4e70..b58eecb9 100644
--- a/internal/next/websvc/http.go
+++ b/internal/next/websvc/http.go
@@ -86,16 +86,24 @@ func (svc *Service) handlePatchSettingsHTTP(w http.ResponseWriter, r *http.Reque
 			return
 		}
 
-		// TODO(a.garipov): !! Add some kind of timeout?  Context?
+		// TODO(a.garipov): Consider better ways to do this.
+		const maxUpdDur = 10 * time.Second
+		updStart := time.Now()
 		var newSvc ServiceWithConfig[*Config]
 		for newSvc = svc.confMgr.Web(); newSvc == svc; {
+			if time.Since(updStart) >= maxUpdDur {
+				log.Error("websvc: failed to update svc after %s", maxUpdDur)
+
+				return
+			}
+
 			log.Debug("websvc: waiting for new websvc to be configured")
 			time.Sleep(1 * time.Second)
 		}
 
 		updErr = newSvc.Start()
 		if updErr != nil {
-			log.Error("websvc: new svc failed to start: %s", updErr)
+			log.Error("websvc: new svc failed to start with error: %s", updErr)
 		}
 	}()
 }