Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent panic if fileinfo is nil #4850

Merged
merged 3 commits into from
Oct 12, 2018
Merged

Prevent panic if fileinfo is nil #4850

merged 3 commits into from
Oct 12, 2018

Conversation

glinton
Copy link
Contributor

@glinton glinton commented Oct 11, 2018

Resolves #4845

@@ -127,6 +128,9 @@ func absDuration(x time.Duration) time.Duration {

func count(basedir string, recursive bool, countFn countFunc) error {
walkFn := func(path string, file os.FileInfo, err error) error {
if file == nil {
return fmt.Errorf("Nil file found at %q", path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the err argument and return it, I think it should have a better error string.

@danielnelson danielnelson added this to the 1.8.2 milestone Oct 12, 2018
@danielnelson danielnelson added the fix pr to fix corresponding bug label Oct 12, 2018
@danielnelson danielnelson changed the base branch from release-1.8 to master October 12, 2018 01:00
@c1982
Copy link

c1982 commented Oct 12, 2018

is this patch active in nightly build?

@danielnelson
Copy link
Contributor

@c1982 Not just yet, but I can give you a link to a CI build if you tell me which one you need.

@c1982
Copy link

c1982 commented Oct 12, 2018

amd64/Windows

@danielnelson
Copy link
Contributor

I imagine you will still have an error reported to the log, just no more crash. It would be interesting to see what is logged. Here is the build:

@c1982
Copy link

c1982 commented Oct 12, 2018

Yes. I tested your version in production. Local service it was not crash. is good.
Also, like you said. Still have an error in log file.

May be help for fix:

2018-10-12T02:22:20Z E! Error in plugin [inputs.filecount]: GetFileAttributesEx Z:\Que\d99be30c85ba478b8a50fe57e52dd78b.eml: The system cannot find the file specified.

This is SMTP queue. So, file is very quickly created and deleted in folder. Plugin try read file attributes but file is gone.

Is possible will add config parameters for attributes reading disabled?

@danielnelson
Copy link
Contributor

Is possible will add config parameters for attributes reading disabled?

We may do this at some point, but I believe will have to stop using the standard library function to walk the directory. It may also conflict with the idea to add file size #4852 but we could make it optional.

In the meantime, I think we should update this PR to call func IsNotExist(err error) bool on the error and if it is true we return nil to continue silently. In this case the file will not be included in the directory count.

@danielnelson danielnelson merged commit 9cc534c into master Oct 12, 2018
@danielnelson danielnelson deleted the bugfix/4845 branch October 12, 2018 21:43
danielnelson pushed a commit that referenced this pull request Oct 12, 2018
@c1982
Copy link

c1982 commented Oct 13, 2018

Thanks. os.IsNotExist(err) condition better than config parameter solution.

rgitzel pushed a commit to rgitzel/telegraf that referenced this pull request Oct 17, 2018
otherpirate pushed a commit to otherpirate/telegraf that referenced this pull request Mar 15, 2019
otherpirate pushed a commit to otherpirate/telegraf that referenced this pull request Mar 15, 2019
dupondje pushed a commit to dupondje/telegraf that referenced this pull request Apr 22, 2019
athoune pushed a commit to bearstech/telegraf that referenced this pull request Apr 17, 2020
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix pr to fix corresponding bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants