mirror of
https://github.com/mudler/LocalAI.git
synced 2026-03-31 13:15:51 -04:00
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 <mudler@users.noreply.github.com> * fix: replace goto statements with break in model deletion loop (fixes CI compilation error) Signed-off-by: LocalAI [bot] <localai-bot@noreply.github.com> * Apply suggestion from @mudler Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com> --------- Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com> Signed-off-by: LocalAI [bot] <localai-bot@noreply.github.com> Co-authored-by: localai-bot <localai-bot@users.noreply.github.com> Co-authored-by: LocalAI [bot] <localai-bot@noreply.github.com> Co-authored-by: Ettore Di Giacinto <mudler@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user