mirror of
https://github.com/mudler/LocalAI
synced 2026-04-21 13:27:21 +00: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:
parent
580517f9db
commit
9e1b0d0c82
1 changed files with 15 additions and 0 deletions
|
|
@ -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)
|
||||
}()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue