diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 8e446aadf709..7c28c5da9e9e 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -33,6 +33,8 @@ https://github.com/elastic/beats/compare/v1.3.0...1.3[Check the HEAD diff] *Filebeat* +- Fix open file handler issue {issue}2028[2028] + *Winlogbeat* ==== Added diff --git a/filebeat/harvester/log.go b/filebeat/harvester/log.go index fdc3f590e668..4681aa0ce068 100644 --- a/filebeat/harvester/log.go +++ b/filebeat/harvester/log.go @@ -227,25 +227,31 @@ func (h *Harvester) openFile() (encoding.Encoding, error) { var encoding encoding.Encoding file, err = input.ReadOpen(h.Path) - if err == nil { - // Check we are not following a rabbit hole (symlinks, etc.) - if !input.IsRegularFile(file) { - return nil, errors.New("Given file is not a regular file.") - } + if err != nil { + logp.Err("Failed opening %s: %s", h.Path, err) + return nil, err + } - encoding, err = h.encoding(file) + // Closes file handler in case of follow up error + defer func() { if err != nil { - - if err == transform.ErrShortSrc { - logp.Info("Initialising encoding for '%v' failed due to file being too short", file) - } else { - logp.Err("Initialising encoding for '%v' failed: %v", file, err) - } - return nil, err + file.Close() } + }() - } else { - logp.Err("Failed opening %s: %s", h.Path, err) + // Check we are not following a rabbit hole (symlinks, etc.) + if !input.IsRegularFile(file) { + return nil, errors.New("Given file is not a regular file.") + } + + encoding, err = h.encoding(file) + if err != nil { + + if err == transform.ErrShortSrc { + logp.Info("Initialising encoding for '%v' failed due to file being too short", file) + } else { + logp.Err("Initialising encoding for '%v' failed: %v", file, err) + } return nil, err }