Skip to content

Commit

Permalink
Fix open file handler issue (#2029)
Browse files Browse the repository at this point in the history
Closes #2028
  • Loading branch information
ruflin authored and tsg committed Jul 19, 2016
1 parent 9601efe commit be76f92
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 21 additions & 15 deletions filebeat/harvester/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit be76f92

Please sign in to comment.