mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-28 06:25:00 +00:00
fix: race during stop of active backends (#5106)
* chore: drop double call to stop all backends, refactors Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix: do lock when cycling to models to delete Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
2f9203cd2a
commit
05f7004487
4 changed files with 45 additions and 37 deletions
|
@ -142,26 +142,6 @@ func (ml *ModelLoader) LoadModel(modelID, modelName string, loader func(string,
|
|||
func (ml *ModelLoader) ShutdownModel(modelName string) error {
|
||||
ml.mu.Lock()
|
||||
defer ml.mu.Unlock()
|
||||
model, ok := ml.models[modelName]
|
||||
if !ok {
|
||||
return fmt.Errorf("model %s not found", modelName)
|
||||
}
|
||||
|
||||
retries := 1
|
||||
for model.GRPC(false, ml.wd).IsBusy() {
|
||||
log.Debug().Msgf("%s busy. Waiting.", modelName)
|
||||
dur := time.Duration(retries*2) * time.Second
|
||||
if dur > retryTimeout {
|
||||
dur = retryTimeout
|
||||
}
|
||||
time.Sleep(dur)
|
||||
retries++
|
||||
|
||||
if retries > 10 && os.Getenv("LOCALAI_FORCE_BACKEND_SHUTDOWN") == "true" {
|
||||
log.Warn().Msgf("Model %s is still busy after %d retries. Forcing shutdown.", modelName, retries)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return ml.deleteProcess(modelName)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue