Skip to content

Commit

Permalink
fix(initializer): correctly reap dangling processes (mudler#3717)
Browse files Browse the repository at this point in the history
Signed-off-by: Ettore Di Giacinto <[email protected]>
  • Loading branch information
mudler authored Oct 2, 2024
1 parent e5586e8 commit 4686877
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions pkg/model/initializers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/model/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/model/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 4686877

Please sign in to comment.