Skip to content

Commit

Permalink
fix: 修复几处日志文件未释放问题 (#5110)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwenode authored and wanghe-fit2cloud committed May 24, 2024
1 parent 8213ada commit 73e901b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions backend/app/service/runtime_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func runComposeCmdWithLog(operate string, composePath string, logPath string) er
global.LOG.Errorf("Failed to open log file: %v", err)
return err
}
defer logFile.Close()
multiWriterStdout := io.MultiWriter(os.Stdout, logFile)
cmd.Stdout = multiWriterStdout
var stderrBuf bytes.Buffer
Expand Down
5 changes: 4 additions & 1 deletion backend/utils/mysql/client/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ func (r *Local) Backup(info BackupInfo) error {
return fmt.Errorf("mkdir %s failed, err: %v", info.TargetDir, err)
}
}
outfile, _ := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755)
outfile, err := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755)
if err == nil {
defer outfile.Close()
}
dumpCmd := "mysqldump"
if r.Type == constant.AppMariaDB {
dumpCmd = "mariadb-dump"
Expand Down
5 changes: 4 additions & 1 deletion backend/utils/mysql/client/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ func (r *Remote) Backup(info BackupInfo) error {
return fmt.Errorf("mkdir %s failed, err: %v", info.TargetDir, err)
}
}
outfile, _ := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755)
outfile, err := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755)
if err == nil {
defer outfile.Close()
}
dumpCmd := "mysqldump"
if r.Type == constant.AppMariaDB {
dumpCmd = "mariadb-dump"
Expand Down
5 changes: 4 additions & 1 deletion backend/utils/postgresql/client/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ func (r *Local) Backup(info BackupInfo) error {
return fmt.Errorf("mkdir %s failed, err: %v", info.TargetDir, err)
}
}
outfile, _ := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755)
outfile, err := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755)
if err == nil {
defer outfile.Close()
}
global.LOG.Infof("start to pg_dump | gzip > %s.gzip", info.TargetDir+"/"+info.FileName)
cmd := exec.Command("docker", "exec", r.ContainerName, "pg_dump", "-F", "c", "-U", r.Username, "-d", info.Name)
gzipCmd := exec.Command("gzip", "-cf")
Expand Down

0 comments on commit 73e901b

Please sign in to comment.