From 9e1b0d0c8266fa4167eb5cd6b978f35f38780f6c Mon Sep 17 00:00:00 2001 From: "LocalAI [bot]" <139863280+localai-bot@users.noreply.github.com> Date: Fri, 6 Mar 2026 01:07:15 +0100 Subject: [PATCH] fix: Add timeout-based wait for model deletion completion (#8756) * fix: Add timeout-based wait for model deletion completion - Replace simple polling loop with context-based timeout (5 minutes) - Use select statement for cleaner timeout handling - Added proper logging for timeout case - This addresses the code review comment about using context with timeout instead of dangerous polling approach * Apply suggestion from @mudler Signed-off-by: Ettore Di Giacinto * fix: replace goto statements with break in model deletion loop (fixes CI compilation error) Signed-off-by: LocalAI [bot] * Apply suggestion from @mudler Signed-off-by: Ettore Di Giacinto --------- Signed-off-by: Ettore Di Giacinto Signed-off-by: LocalAI [bot] Co-authored-by: localai-bot Co-authored-by: LocalAI [bot] Co-authored-by: Ettore Di Giacinto --- core/http/routes/ui_api.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/http/routes/ui_api.go b/core/http/routes/ui_api.go index 563c9b499..446086767 100644 --- a/core/http/routes/ui_api.go +++ b/core/http/routes/ui_api.go @@ -509,6 +509,21 @@ func RegisterUIAPIRoutes(app *echo.Echo, cl *config.ModelConfigLoader, ml *model galleryService.StoreCancellation(uid, cancelFunc) go func() { galleryService.ModelGalleryChannel <- op + // Wait for the deletion operation to complete with a timeout + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + for { + select { + case <-ctx.Done(): + xlog.Warn("Timeout waiting for deletion to complete", "uid", uid) + break + default: + if status := galleryService.GetStatus(uid); status != nil && status.Processed { + break + } + time.Sleep(100 * time.Millisecond) + } + } cl.RemoveModelConfig(galleryName) }()