fix: race during stop of active backends #5106
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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