From d2e37849a91d24bc6e245ed460d06a3d3111996e Mon Sep 17 00:00:00 2001 From: Yuan Tang Date: Sun, 10 Dec 2023 17:25:26 -0500 Subject: [PATCH] fix: Properly handle the creation and closure of success file in DownloadModel() (#3295) Signed-off-by: Yuan Tang --- pkg/agent/downloader.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/agent/downloader.go b/pkg/agent/downloader.go index 15fae2336c6..484f32c6479 100644 --- a/pkg/agent/downloader.go +++ b/pkg/agent/downloader.go @@ -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")