Skip to content

Commit

Permalink
fix: Properly handle the creation and closure of success file in Down…
Browse files Browse the repository at this point in the history
…loadModel() (kserve#3295)

Signed-off-by: Yuan Tang <[email protected]>
  • Loading branch information
terrytangyuan authored Dec 10, 2023
1 parent 2874730 commit d2e3784
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/agent/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ func (d *Downloader) DownloadModel(modelName string, modelSpec *v1alpha1.ModelSp
return errors.Wrapf(err, "failed to download model")
}
file, createErr := storage.Create(successFile)
defer file.Close()
if createErr != nil {
return errors.Wrapf(createErr, "failed to create success file")
}
defer func(file *os.File) {
err := file.Close()
if err != nil {
d.Logger.Errorf("Failed to close created file %v", err)
}
}(file)
encodedJson, err := json.Marshal(modelSpec)
if err != nil {
return errors.Wrapf(createErr, "failed to encode model spec")
Expand Down

0 comments on commit d2e3784

Please sign in to comment.