From c3dd6f2e0addaacf6412b6010a74736346ea8d19 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 25 Apr 2024 16:45:12 +0800 Subject: [PATCH] =?UTF-8?q?pref:=20=E9=87=8A=E6=94=BE=E5=AE=B9=E5=99=A8=20?= =?UTF-8?q?client=20=E8=BF=9E=E6=8E=A5=20(#4700)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/file.go | 2 ++ backend/app/service/app.go | 3 +++ backend/app/service/app_install.go | 1 + backend/app/service/app_utils.go | 7 +++-- backend/app/service/container.go | 17 ++++++++++-- backend/app/service/container_compose.go | 4 ++- backend/app/service/container_network.go | 4 +++ backend/app/service/container_volume.go | 3 +++ backend/app/service/docker.go | 2 ++ backend/app/service/image.go | 16 +++++++++-- backend/app/service/nginx.go | 4 ++- backend/app/service/runtime.go | 17 +++++++----- backend/app/service/runtime_utils.go | 27 ++++++++++++------- .../utils/cloud_storage/client/onedrive.go | 4 +-- backend/utils/cloud_storage/client/sftp.go | 2 +- backend/utils/docker/docker.go | 5 ++++ backend/utils/http/get.go | 4 ++- backend/utils/postgresql/client/remote.go | 1 + 18 files changed, 95 insertions(+), 28 deletions(-) diff --git a/backend/app/api/v1/file.go b/backend/app/api/v1/file.go index 1075df6ae..eee2f925f 100644 --- a/backend/app/api/v1/file.go +++ b/backend/app/api/v1/file.go @@ -486,6 +486,7 @@ func (b *BaseApi) Download(c *gin.Context) { if err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) } + defer file.Close() info, _ := file.Stat() c.Header("Content-Length", strconv.FormatInt(info.Size(), 10)) c.Header("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(info.Name())) @@ -643,6 +644,7 @@ func (b *BaseApi) UploadChunkFiles(c *gin.Context) { helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) return } + defer uploadFile.Close() chunkIndex, err := strconv.Atoi(c.PostForm("chunkIndex")) if err != nil { helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) diff --git a/backend/app/service/app.go b/backend/app/service/app.go index 61c7034c1..ee840f80d 100644 --- a/backend/app/service/app.go +++ b/backend/app/service/app.go @@ -230,6 +230,7 @@ func (a AppService) GetAppDetail(appID uint, version, appType string) (response. if err != nil { return appDetailDTO, buserr.WithDetail("ErrGetCompose", err.Error(), err) } + defer composeRes.Body.Close() bodyContent, err := io.ReadAll(composeRes.Body) if err != nil { return appDetailDTO, buserr.WithDetail("ErrGetCompose", err.Error(), err) @@ -835,6 +836,7 @@ func (a AppService) SyncAppListFromRemote() (err error) { if err != nil { return err } + defer iconRes.Body.Close() body, err := io.ReadAll(iconRes.Body) if err != nil { return err @@ -862,6 +864,7 @@ func (a AppService) SyncAppListFromRemote() (err error) { if err != nil { return err } + defer composeRes.Body.Close() bodyContent, err := io.ReadAll(composeRes.Body) if err != nil { return err diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index ab5f06843..0069766c4 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -712,6 +712,7 @@ func syncAppInstallStatus(appInstall *model.AppInstall) error { if err != nil { return err } + defer cli.Close() containers, err := cli.ListContainersByName(containerNames) if err != nil { return err diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index 246e044ba..693235b78 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -5,8 +5,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/1Panel-dev/1Panel/backend/utils/xpack" - "github.com/docker/docker/api/types/container" "math" "net/http" "os" @@ -17,6 +15,9 @@ import ( "strconv" "strings" + "github.com/1Panel-dev/1Panel/backend/utils/xpack" + "github.com/docker/docker/api/types/container" + "github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" @@ -596,6 +597,7 @@ func upgradeInstall(installID uint, detailID uint, backup, pullImage bool) error upErr = err return } + defer dockerCli.Close() for _, image := range images { global.LOG.Infof(i18n.GetMsgWithName("PullImageStart", image, nil)) if err = dockerCli.PullImage(image, true); err != nil { @@ -853,6 +855,7 @@ func checkContainerNameIsExist(containerName, appDir string) (bool, error) { if err != nil { return false, err } + defer client.Close() var options container.ListOptions list, err := client.ContainerList(context.Background(), options) if err != nil { diff --git a/backend/app/service/container.go b/backend/app/service/container.go index 4fd22905e..88148d84a 100644 --- a/backend/app/service/container.go +++ b/backend/app/service/container.go @@ -88,6 +88,7 @@ func (u *ContainerService) Page(req dto.PageContainer) (int64, interface{}, erro if err != nil { return 0, nil, err } + defer client.Close() options := container.ListOptions{ All: true, } @@ -219,6 +220,7 @@ func (u *ContainerService) List() ([]string, error) { if err != nil { return nil, err } + defer client.Close() containers, err := client.ContainerList(context.Background(), container.ListOptions{All: true}) if err != nil { return nil, err @@ -240,6 +242,7 @@ func (u *ContainerService) ContainerListStats() ([]dto.ContainerListStats, error if err != nil { return nil, err } + defer client.Close() list, err := client.ContainerList(context.Background(), container.ListOptions{All: true}) if err != nil { return nil, err @@ -262,6 +265,7 @@ func (u *ContainerService) Inspect(req dto.InspectReq) (string, error) { if err != nil { return "", err } + defer client.Close() var inspectInfo interface{} switch req.Type { case "container": @@ -289,6 +293,7 @@ func (u *ContainerService) Prune(req dto.ContainerPrune) (dto.ContainerPruneRepo if err != nil { return report, err } + defer client.Close() pruneFilters := filters.NewArgs() if req.WithTagAll { pruneFilters.Add("dangling", "false") @@ -350,6 +355,7 @@ func (u *ContainerService) ContainerCreate(req dto.ContainerOperate) error { if err != nil { return err } + defer client.Close() ctx := context.Background() newContainer, _ := client.ContainerInspect(ctx, req.Name) if newContainer.ContainerJSONBase != nil { @@ -397,6 +403,7 @@ func (u *ContainerService) ContainerInfo(req dto.OperationWithName) (*dto.Contai if err != nil { return nil, err } + defer client.Close() ctx := context.Background() oldContainer, err := client.ContainerInspect(ctx, req.Name) if err != nil { @@ -467,6 +474,7 @@ func (u *ContainerService) ContainerUpdate(req dto.ContainerOperate) error { if err != nil { return err } + defer client.Close() ctx := context.Background() newContainer, _ := client.ContainerInspect(ctx, req.Name) if newContainer.ContainerJSONBase != nil && newContainer.ID != req.ContainerID { @@ -515,6 +523,7 @@ func (u *ContainerService) ContainerUpgrade(req dto.ContainerUpgrade) error { if err != nil { return err } + defer client.Close() ctx := context.Background() oldContainer, err := client.ContainerInspect(ctx, req.Name) if err != nil { @@ -562,6 +571,7 @@ func (u *ContainerService) ContainerRename(req dto.ContainerRename) error { if err != nil { return err } + defer client.Close() newContainer, _ := client.ContainerInspect(ctx, req.NewName) if newContainer.ContainerJSONBase != nil { @@ -577,6 +587,7 @@ func (u *ContainerService) ContainerOperation(req dto.ContainerOperation) error if err != nil { return err } + defer client.Close() for _, item := range req.Names { global.LOG.Infof("start container %s operation %s", item, req.Operation) switch req.Operation { @@ -604,6 +615,7 @@ func (u *ContainerService) ContainerLogClean(req dto.OperationWithName) error { if err != nil { return err } + defer client.Close() ctx := context.Background() containerItem, err := client.ContainerInspect(ctx, req.Name) if err != nil { @@ -722,6 +734,7 @@ func (u *ContainerService) ContainerStats(id string) (*dto.ContainerStats, error if err != nil { return nil, err } + defer client.Close() res, err := client.ContainerStats(context.TODO(), id, false) if err != nil { return nil, err @@ -757,6 +770,7 @@ func (u *ContainerService) LoadContainerLogs(req dto.OperationWithNameAndType) s if err != nil { return "" } + defer cli.Close() options := container.ListOptions{All: true} options.Filters = filters.NewArgs() options.Filters.Add("label", fmt.Sprintf("%s=%s", composeProjectLabel, req.Name)) @@ -897,12 +911,11 @@ func loadCpuAndMem(client *client.Client, container string) dto.ContainerListSta return data } + defer res.Body.Close() body, err := io.ReadAll(res.Body) if err != nil { - res.Body.Close() return data } - res.Body.Close() var stats *types.StatsJSON if err := json.Unmarshal(body, &stats); err != nil { return data diff --git a/backend/app/service/container_compose.go b/backend/app/service/container_compose.go index 0765a52af..e09e1f64c 100644 --- a/backend/app/service/container_compose.go +++ b/backend/app/service/container_compose.go @@ -4,7 +4,6 @@ import ( "bufio" "errors" "fmt" - "github.com/docker/docker/api/types/container" "io" "os" "os/exec" @@ -13,6 +12,8 @@ import ( "strings" "time" + "github.com/docker/docker/api/types/container" + "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/app/model" "github.com/1Panel-dev/1Panel/backend/buserr" @@ -39,6 +40,7 @@ func (u *ContainerService) PageCompose(req dto.SearchWithPage) (int64, interface if err != nil { return 0, nil, err } + defer client.Close() options := container.ListOptions{All: true} options.Filters = filters.NewArgs() diff --git a/backend/app/service/container_network.go b/backend/app/service/container_network.go index a3a890772..44424e914 100644 --- a/backend/app/service/container_network.go +++ b/backend/app/service/container_network.go @@ -19,6 +19,7 @@ func (u *ContainerService) PageNetwork(req dto.SearchWithPage) (int64, interface if err != nil { return 0, nil, err } + defer client.Close() list, err := client.NetworkList(context.TODO(), types.NetworkListOptions{}) if err != nil { return 0, nil, err @@ -81,6 +82,7 @@ func (u *ContainerService) ListNetwork() ([]dto.Options, error) { if err != nil { return nil, err } + defer client.Close() list, err := client.NetworkList(context.TODO(), types.NetworkListOptions{}) if err != nil { return nil, err @@ -100,6 +102,7 @@ func (u *ContainerService) DeleteNetwork(req dto.BatchDelete) error { if err != nil { return err } + defer client.Close() for _, id := range req.Names { if err := client.NetworkRemove(context.TODO(), id); err != nil { if strings.Contains(err.Error(), "has active endpoints") { @@ -115,6 +118,7 @@ func (u *ContainerService) CreateNetwork(req dto.NetworkCreate) error { if err != nil { return err } + defer client.Close() var ( ipams []network.IPAMConfig enableV6 bool diff --git a/backend/app/service/container_volume.go b/backend/app/service/container_volume.go index d2005e19a..daaa49b4c 100644 --- a/backend/app/service/container_volume.go +++ b/backend/app/service/container_volume.go @@ -82,6 +82,7 @@ func (u *ContainerService) ListVolume() ([]dto.Options, error) { if err != nil { return nil, err } + defer client.Close() list, err := client.VolumeList(context.TODO(), volume.ListOptions{}) if err != nil { return nil, err @@ -102,6 +103,7 @@ func (u *ContainerService) DeleteVolume(req dto.BatchDelete) error { if err != nil { return err } + defer client.Close() for _, id := range req.Names { if err := client.VolumeRemove(context.TODO(), id, true); err != nil { if strings.Contains(err.Error(), "volume is in use") { @@ -117,6 +119,7 @@ func (u *ContainerService) CreateVolume(req dto.VolumeCreate) error { if err != nil { return err } + defer client.Close() arg := filters.NewArgs() arg.Add("name", req.Name) vos, _ := client.VolumeList(context.TODO(), volume.ListOptions{Filters: arg}) diff --git a/backend/app/service/docker.go b/backend/app/service/docker.go index 371538732..c531721ce 100644 --- a/backend/app/service/docker.go +++ b/backend/app/service/docker.go @@ -55,6 +55,7 @@ func (u *DockerService) LoadDockerStatus() string { if err != nil { return constant.Stopped } + defer client.Close() if _, err := client.Ping(context.Background()); err != nil { return constant.Stopped } @@ -72,6 +73,7 @@ func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf { if err != nil { data.Status = constant.Stopped } else { + defer client.Close() if _, err := client.Ping(ctx); err != nil { data.Status = constant.Stopped } diff --git a/backend/app/service/image.go b/backend/app/service/image.go index c1a23af52..2fb4008d7 100644 --- a/backend/app/service/image.go +++ b/backend/app/service/image.go @@ -7,14 +7,15 @@ import ( "encoding/json" "errors" "fmt" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/image" "io" "os" "path" "strings" "time" + "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/image" + "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/buserr" "github.com/1Panel-dev/1Panel/backend/constant" @@ -53,6 +54,7 @@ func (u *ImageService) Page(req dto.SearchWithPage) (int64, interface{}, error) if err != nil { return 0, nil, err } + defer client.Close() list, err = client.ImageList(context.Background(), image.ListOptions{}) if err != nil { return 0, nil, err @@ -106,6 +108,7 @@ func (u *ImageService) ListAll() ([]dto.ImageInfo, error) { if err != nil { return nil, err } + defer client.Close() list, err := client.ImageList(context.Background(), image.ListOptions{}) if err != nil { return nil, err @@ -133,6 +136,7 @@ func (u *ImageService) List() ([]dto.Options, error) { if err != nil { return nil, err } + defer client.Close() list, err = client.ImageList(context.Background(), image.ListOptions{}) if err != nil { return nil, err @@ -152,6 +156,7 @@ func (u *ImageService) ImageBuild(req dto.ImageBuild) (string, error) { if err != nil { return "", err } + defer client.Close() fileName := "Dockerfile" if req.From == "edit" { dir := fmt.Sprintf("%s/docker/build/%s", constant.DataDir, strings.ReplaceAll(req.Name, ":", "_")) @@ -235,6 +240,7 @@ func (u *ImageService) ImagePull(req dto.ImagePull) (string, error) { if err != nil { return "", err } + defer client.Close() dockerLogDir := path.Join(global.CONF.System.TmpDir, "docker_logs") if _, err := os.Stat(dockerLogDir); err != nil && os.IsNotExist(err) { if err = os.MkdirAll(dockerLogDir, os.ModePerm); err != nil { @@ -305,10 +311,12 @@ func (u *ImageService) ImageLoad(req dto.ImageLoad) error { if err != nil { return err } + defer client.Close() res, err := client.ImageLoad(context.TODO(), file, true) if err != nil { return err } + defer res.Body.Close() content, err := io.ReadAll(res.Body) if err != nil { return err @@ -324,6 +332,7 @@ func (u *ImageService) ImageSave(req dto.ImageSave) error { if err != nil { return err } + defer client.Close() out, err := client.ImageSave(context.TODO(), []string{req.TagName}) if err != nil { @@ -346,6 +355,7 @@ func (u *ImageService) ImageTag(req dto.ImageTag) error { if err != nil { return err } + defer client.Close() if err := client.ImageTag(context.TODO(), req.SourceID, req.TargetName); err != nil { return err @@ -358,6 +368,7 @@ func (u *ImageService) ImagePush(req dto.ImagePush) (string, error) { if err != nil { return "", err } + defer client.Close() repo, err := imageRepoRepo.Get(commonRepo.WithByID(req.RepoID)) if err != nil { return "", err @@ -416,6 +427,7 @@ func (u *ImageService) ImageRemove(req dto.BatchDelete) error { if err != nil { return err } + defer client.Close() for _, id := range req.Names { if _, err := client.ImageRemove(context.TODO(), id, types.ImageRemoveOptions{Force: req.Force, PruneChildren: true}); err != nil { if strings.Contains(err.Error(), "image is being used") || strings.Contains(err.Error(), "is using") { diff --git a/backend/app/service/nginx.go b/backend/app/service/nginx.go index d6891482e..0e4ae72e3 100644 --- a/backend/app/service/nginx.go +++ b/backend/app/service/nginx.go @@ -2,7 +2,6 @@ package service import ( "fmt" - "github.com/1Panel-dev/1Panel/backend/utils/compose" "io" "net/http" "os" @@ -10,6 +9,8 @@ import ( "strings" "time" + "github.com/1Panel-dev/1Panel/backend/utils/compose" + "github.com/1Panel-dev/1Panel/backend/app/dto/request" "github.com/1Panel-dev/1Panel/backend/app/dto/response" @@ -76,6 +77,7 @@ func (n NginxService) GetStatus() (response.NginxStatus, error) { if err != nil { return response.NginxStatus{}, err } + defer res.Body.Close() content, err := io.ReadAll(res.Body) if err != nil { return response.NginxStatus{}, err diff --git a/backend/app/service/runtime.go b/backend/app/service/runtime.go index 8b3fe18ce..9b780825f 100644 --- a/backend/app/service/runtime.go +++ b/backend/app/service/runtime.go @@ -4,6 +4,14 @@ import ( "context" "encoding/json" "fmt" + "os" + "path" + "path/filepath" + "regexp" + "strconv" + "strings" + "time" + "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto/request" "github.com/1Panel-dev/1Panel/backend/app/dto/response" @@ -19,13 +27,6 @@ import ( "github.com/1Panel-dev/1Panel/backend/utils/files" "github.com/pkg/errors" "github.com/subosito/gotenv" - "os" - "path" - "path/filepath" - "regexp" - "strconv" - "strings" - "time" ) type RuntimeService struct { @@ -193,6 +194,7 @@ func (r *RuntimeService) Delete(runtimeDelete request.RuntimeDelete) error { if err != nil { return err } + defer client.Close() imageID, err := client.GetImageIDByName(runtime.Image) if err != nil { return err @@ -420,6 +422,7 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error { if err != nil { return err } + defer client.Close() imageID, err := client.GetImageIDByName(oldImage) if err != nil { return err diff --git a/backend/app/service/runtime_utils.go b/backend/app/service/runtime_utils.go index 5ade63e7c..31ffa6a0a 100644 --- a/backend/app/service/runtime_utils.go +++ b/backend/app/service/runtime_utils.go @@ -3,6 +3,15 @@ package service import ( "bytes" "fmt" + "io" + "net/http" + "os" + "os/exec" + "path" + "path/filepath" + "strings" + "time" + "github.com/1Panel-dev/1Panel/backend/app/dto/request" "github.com/1Panel-dev/1Panel/backend/app/model" "github.com/1Panel-dev/1Panel/backend/buserr" @@ -13,14 +22,6 @@ import ( "github.com/pkg/errors" "github.com/subosito/gotenv" "gopkg.in/yaml.v3" - "io" - "net/http" - "os" - "os/exec" - "path" - "path/filepath" - "strings" - "time" ) func handleNode(create request.RuntimeCreate, runtime *model.Runtime, fileOp files.FileOp, appVersionDir string) (err error) { @@ -53,7 +54,12 @@ func handleNode(create request.RuntimeCreate, runtime *model.Runtime, fileOp fil } go func() { - _, _ = http.Get(nodeDetail.DownloadCallBackUrl) + res, err := http.Get(nodeDetail.DownloadCallBackUrl) + if err != nil { + global.LOG.Errorf("http request failed(handleNode), err: %v", err) + return + } + res.Body.Close() }() go startRuntime(runtime) @@ -172,6 +178,7 @@ func SyncRuntimeContainerStatus(runtime *model.Runtime) error { if err != nil { return err } + defer cli.Close() containers, err := cli.ListContainersByName(containerNames) if err != nil { return err @@ -228,6 +235,7 @@ func buildRuntime(runtime *model.Runtime, oldImageID string, rebuild bool) { if oldImageID != "" { client, err := docker.NewClient() if err == nil { + defer client.Close() newImageID, err := client.GetImageIDByName(runtime.Image) if err == nil && newImageID != oldImageID { global.LOG.Infof("delete imageID [%s] ", oldImageID) @@ -390,6 +398,7 @@ func checkContainerName(name string) error { if err != nil { return err } + defer dockerCli.Close() names, err := dockerCli.ListContainersByName([]string{name}) if err != nil { return err diff --git a/backend/utils/cloud_storage/client/onedrive.go b/backend/utils/cloud_storage/client/onedrive.go index 99dabd5b3..afd18bad3 100644 --- a/backend/utils/cloud_storage/client/onedrive.go +++ b/backend/utils/cloud_storage/client/onedrive.go @@ -223,11 +223,11 @@ func RefreshToken(grantType string, varMap map[string]interface{}) (string, stri if err != nil { return "", "", fmt.Errorf("request for access token failed, err: %v", err) } + defer resp.Body.Close() respBody, err := io.ReadAll(resp.Body) if err != nil { return "", "", fmt.Errorf("read data from response body failed, err: %v", err) } - defer resp.Body.Close() tokenMap := map[string]interface{}{} if err := json.Unmarshal(respBody, &tokenMap); err != nil { @@ -387,9 +387,9 @@ func (o *oneDriveClient) upBig(ctx context.Context, srcPath, folderID string, fi if err != nil { return false, err } + res.Body.Close() if res.StatusCode != 201 && res.StatusCode != 202 && res.StatusCode != 200 { data, _ := io.ReadAll(res.Body) - res.Body.Close() return false, errors.New(string(data)) } } diff --git a/backend/utils/cloud_storage/client/sftp.go b/backend/utils/cloud_storage/client/sftp.go index b48b10cde..d544315bf 100644 --- a/backend/utils/cloud_storage/client/sftp.go +++ b/backend/utils/cloud_storage/client/sftp.go @@ -50,12 +50,12 @@ func (s sftpClient) Upload(src, target string) (bool, error) { if err != nil { return false, err } + defer sshClient.Close() client, err := sftp.NewClient(sshClient) if err != nil { return false, err } defer client.Close() - defer sshClient.Close() srcFile, err := os.Open(src) if err != nil { diff --git a/backend/utils/docker/docker.go b/backend/utils/docker/docker.go index 03d52936c..0e5e116cb 100644 --- a/backend/utils/docker/docker.go +++ b/backend/utils/docker/docker.go @@ -33,6 +33,10 @@ func NewClient() (Client, error) { }, nil } +func (c Client) Close() { + _ = c.cli.Close() +} + func NewDockerClient() (*client.Client, error) { var settingItem model.Setting _ = global.DB.Where("key = ?", "DockerSockPath").First(&settingItem).Error @@ -150,6 +154,7 @@ func CreateDefaultDockerNetwork() error { global.LOG.Errorf("init docker client error %s", err.Error()) return err } + defer cli.Close() if !cli.NetworkExist("1panel-network") { if err := cli.CreateNetwork("1panel-network"); err != nil { global.LOG.Errorf("create default docker network error %s", err.Error()) diff --git a/backend/utils/http/get.go b/backend/utils/http/get.go index bacdc865c..1f8255d6c 100644 --- a/backend/utils/http/get.go +++ b/backend/utils/http/get.go @@ -4,11 +4,12 @@ import ( "context" "crypto/tls" "errors" - "github.com/1Panel-dev/1Panel/backend/buserr" "net" "net/http" "strings" "time" + + "github.com/1Panel-dev/1Panel/backend/buserr" ) func GetHttpRes(url string) (*http.Response, error) { @@ -42,6 +43,7 @@ func GetHttpRes(url string) (*http.Response, error) { return nil, buserr.WithMap("ErrHttpReqFailed", map[string]interface{}{"err": err.Error()}, err) } } + defer resp.Body.Close() if resp.StatusCode == 404 { return nil, buserr.New("ErrHttpReqNotFound") } diff --git a/backend/utils/postgresql/client/remote.go b/backend/utils/postgresql/client/remote.go index 77626d69a..c7e2db37a 100644 --- a/backend/utils/postgresql/client/remote.go +++ b/backend/utils/postgresql/client/remote.go @@ -269,6 +269,7 @@ func loadImageTag() (string, error) { if err != nil { return "", err } + defer client.Close() images, err := client.ImageList(context.Background(), types.ImageListOptions{}) if err != nil { return "", err