Merge pull request #3172 from chengzhichao-xydt/codex/close-error-checks-clean
fix: explicitly ignore Close() errors in error paths and retry loops
This commit is contained in:
commit
124c529bf1
4 changed files with 9 additions and 9 deletions
|
|
@ -569,7 +569,7 @@ func (t *ExecTool) runBackground(ctx context.Context, command, cwd string, ptyEn
|
||||||
// with synchronous exec runs.
|
// with synchronous exec runs.
|
||||||
if err := isolation.Start(cmd); err != nil {
|
if err := isolation.Start(cmd); err != nil {
|
||||||
if session.ptyMaster != nil {
|
if session.ptyMaster != nil {
|
||||||
session.ptyMaster.Close()
|
_ = session.ptyMaster.Close()
|
||||||
}
|
}
|
||||||
return ErrorResult(fmt.Sprintf("failed to start command: %v", err))
|
return ErrorResult(fmt.Sprintf("failed to start command: %v", err))
|
||||||
}
|
}
|
||||||
|
|
@ -698,7 +698,7 @@ func (t *ExecTool) runBackground(ctx context.Context, command, cwd string, ptyEn
|
||||||
|
|
||||||
// All pipes closed, get exit status
|
// All pipes closed, get exit status
|
||||||
if stdinWriter != nil {
|
if stdinWriter != nil {
|
||||||
stdinWriter.Close()
|
_ = stdinWriter.Close()
|
||||||
}
|
}
|
||||||
cmd.Wait()
|
cmd.Wait()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -576,16 +576,16 @@ func extractZip(archivePath, destDir string) error {
|
||||||
}
|
}
|
||||||
out, err := os.OpenFile(target, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, f.FileInfo().Mode())
|
out, err := os.OpenFile(target, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, f.FileInfo().Mode())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rc.Close()
|
_ = rc.Close()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := io.Copy(out, rc); err != nil {
|
if _, err := io.Copy(out, rc); err != nil {
|
||||||
rc.Close()
|
_ = rc.Close()
|
||||||
out.Close()
|
_ = out.Close()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := rc.Close(); err != nil {
|
if err := rc.Close(); err != nil {
|
||||||
out.Close()
|
_ = out.Close()
|
||||||
return fmt.Errorf("close zip entry reader: %w", err)
|
return fmt.Errorf("close zip entry reader: %w", err)
|
||||||
}
|
}
|
||||||
if err := out.Close(); err != nil {
|
if err := out.Close(); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ func DoRequestWithRetry(client *http.Client, req *http.Request) (*http.Response,
|
||||||
|
|
||||||
for i := range maxRetries {
|
for i := range maxRetries {
|
||||||
if i > 0 && resp != nil {
|
if i > 0 && resp != nil {
|
||||||
resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err = client.Do(req)
|
resp, err = client.Do(req)
|
||||||
|
|
@ -42,7 +42,7 @@ func DoRequestWithRetry(client *http.Client, req *http.Request) (*http.Response,
|
||||||
if i < maxRetries-1 {
|
if i < maxRetries-1 {
|
||||||
if err = sleepWithCtx(req.Context(), retryDelayForAttempt(resp, i)); err != nil {
|
if err = sleepWithCtx(req.Context(), retryDelayForAttempt(resp, i)); err != nil {
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("failed to sleep: %w", err)
|
return nil, fmt.Errorf("failed to sleep: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,7 @@ func DownloadFile(urlStr, filename string, opts DownloadOptions) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := io.Copy(out, resp.Body); err != nil {
|
if _, err := io.Copy(out, resp.Body); err != nil {
|
||||||
out.Close()
|
_ = out.Close()
|
||||||
os.Remove(localPath)
|
os.Remove(localPath)
|
||||||
logger.ErrorCF(opts.LoggerPrefix, "Failed to write file", map[string]any{
|
logger.ErrorCF(opts.LoggerPrefix, "Failed to write file", map[string]any{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue