-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: race during stop of active backends #5106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
✅ Deploy Preview for localai ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses a race condition during the shutdown of active backends by refactoring the shutdown logic. Key changes include refactoring the deletion logic in deleteProcess with a retry loop, replacing the old ShutdownModel in loader.go with deleteProcess, and refining stopActiveBackends behavior based on the singleActiveBackend flag.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
pkg/model/process.go | Refactored deleteProcess to include a retry loop and forced shutdown |
pkg/model/loader.go | Removed outdated shutdown logic and now calls deleteProcess |
pkg/model/initializers.go | Adjusted stopActiveBackends logic for proper single backend handling |
Files not reviewed (1)
- .env: Language not supported
@@ -44,9 +62,12 @@ func (ml *ModelLoader) deleteProcess(s string) error { | |||
|
|||
func (ml *ModelLoader) StopGRPC(filter GRPCProcessFilter) error { | |||
var err error = nil | |||
ml.mu.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we were missing the lock when iterating over models
Description
This PR is a small refactor while I was walking out the code, and found a potential race condition.
This pull request introduces several changes to improve the handling of backend shutdowns and model loading in the
pkg/model
package. The key changes include adding a new environment variable to force backend shutdown, refactoring thedeleteProcess
method, and ensuring proper backend management during model loading.Backend shutdown improvements:
.env
: Added a new environment variableLOCALAI_FORCE_BACKEND_SHUTDOWN
to force the shutdown of backends if they are busy.pkg/model/process.go
: Refactored thedeleteProcess
method to handle retries and force shutdown if the backend is busy, using the new environment variable. [1] [2]Model loading enhancements:
pkg/model/initializers.go
: Modified thestopActiveBackends
method to return early ifsingleActiveBackend
is not set, and added comments to clarify the backend loading process. [1] [2] [3]pkg/model/loader.go
: Removed the busy-wait loop from theShutdownModel
method, delegating the shutdown process to thedeleteProcess
method.Notes for Reviewers
Signed commits