From 4686877c6dc216a87e835bfb0db2b2fcda7e8300 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Wed, 2 Oct 2024 20:37:40 +0200 Subject: [PATCH] fix(initializer): correctly reap dangling processes (#3717) Signed-off-by: Ettore Di Giacinto --- pkg/model/initializers.go | 12 +++++++++--- pkg/model/loader.go | 2 +- pkg/model/process.go | 4 ++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/model/initializers.go b/pkg/model/initializers.go index 6f56b4536089..9ecd77a61a58 100644 --- a/pkg/model/initializers.go +++ b/pkg/model/initializers.go @@ -376,7 +376,9 @@ func (ml *ModelLoader) grpcModel(backend string, o *Options) func(string, string if !ready { log.Debug().Msgf("GRPC Service NOT ready") - ml.deleteProcess(o.model) + if process := client.Process(); process != nil { + process.Stop() + } return nil, fmt.Errorf("grpc service not ready") } @@ -388,11 +390,15 @@ func (ml *ModelLoader) grpcModel(backend string, o *Options) func(string, string res, err := client.GRPC(o.parallelRequests, ml.wd).LoadModel(o.context, &options) if err != nil { - ml.deleteProcess(o.model) + if process := client.Process(); process != nil { + process.Stop() + } return nil, fmt.Errorf("could not load model: %w", err) } if !res.Success { - ml.deleteProcess(o.model) + if process := client.Process(); process != nil { + process.Stop() + } return nil, fmt.Errorf("could not load model (no success): %s", res.Message) } diff --git a/pkg/model/loader.go b/pkg/model/loader.go index 97e62fe4fb43..0dcc99153b65 100644 --- a/pkg/model/loader.go +++ b/pkg/model/loader.go @@ -128,7 +128,7 @@ func (ml *ModelLoader) LoadModel(modelID, modelName string, loader func(string, defer ml.mu.Unlock() model, err := loader(modelID, modelName, modelFile) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to load model with internal loader: %s", err) } if model == nil { diff --git a/pkg/model/process.go b/pkg/model/process.go index 3e16ddafcefd..c27fbda395f3 100644 --- a/pkg/model/process.go +++ b/pkg/model/process.go @@ -18,14 +18,18 @@ import ( func (ml *ModelLoader) deleteProcess(s string) error { defer delete(ml.models, s) + log.Debug().Msgf("Deleting process %s", s) + m, exists := ml.models[s] if !exists { + log.Error().Msgf("Model does not exist %s", s) // Nothing to do return nil } process := m.Process() if process == nil { + log.Error().Msgf("No process for %s", s) // Nothing to do as there is no process return nil }