Skip to content

Commit

Permalink
[Ingest Manager] Change Sync/Close call order (elastic#21735)
Browse files Browse the repository at this point in the history
[Ingest Manager] Change Sync/Close call order (elastic#21735)
  • Loading branch information
michalpristas committed Oct 14, 2020
1 parent 09c3096 commit 0d8e731
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
14 changes: 9 additions & 5 deletions x-pack/elastic-agent/pkg/artifact/install/tar/tar_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,19 @@ func unpack(r io.Reader, dir string) error {
}

_, err = io.Copy(wf, tr)

if err == nil {
// sometimes we try executing binary too fast and run into text file busy after unpacking
// syncing prevents this
if syncErr := wf.Sync(); syncErr != nil {
err = syncErr
}
}

if closeErr := wf.Close(); closeErr != nil && err == nil {
err = closeErr
}

// sometimes we try executing binary too fast and run into text file busy after unpacking
// syncing prevents this
if syncErr := wf.Sync(); syncErr != nil && err == nil {
err = syncErr
}
if err != nil {
return fmt.Errorf("TarInstaller: error writing to %s: %v", abs, err)
}
Expand Down
11 changes: 4 additions & 7 deletions x-pack/elastic-agent/pkg/artifact/install/zip/zip_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,15 @@ func (i *Installer) unzip(artifactPath string) error {
if closeErr := f.Close(); closeErr != nil {
err = multierror.Append(err, closeErr)
}

// sometimes we try executing binary too fast and run into text file busy after unpacking
// syncing prevents this
if syncErr := f.Sync(); syncErr != nil {
err = multierror.Append(err, syncErr)
}

}()

if _, err = io.Copy(f, rc); err != nil {
return err
}

// sometimes we try executing binary too fast and run into text file busy after unpacking
// syncing prevents this
f.Sync()
}
return nil
}
Expand Down

0 comments on commit 0d8e731

Please sign in to comment.