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

attempt at fix dungbeetle alert #213

Merged
merged 2 commits into from
Mar 11, 2020
Merged

attempt at fix dungbeetle alert #213

merged 2 commits into from
Mar 11, 2020

Conversation

buzinsky
Copy link

@buzinsky buzinsky commented Mar 2, 2020

Right now untested. The errors seem to suggest that this is totally coming from the getsize() call which only happens here. When it acts on a file that does not exist, it throws this error.

This should be fixed by this change, as isfile(x) is not logically the same as not isdir(x). While they are the same statements if I put x = filename or directory name (true, false respectively), when the file does not exist, the statements are not the same. We now check explicitly that this is a real file

Resolves #212

@buzinsky buzinsky requested a review from wcpettus March 2, 2020 16:32
@wcpettus
Copy link

wcpettus commented Mar 2, 2020

I think there may still be an unhandled race condition, albeit we've decreased the cross-section for this happening -

Should we do something more generic? If we wrap everything starting here:
https://github.com/project8/dragonfly/blob/master/dragonfly/implementations/dungbeetle.py#L51
in a try/except OSError block, we could catch every possible race condition. We could even give a different warning message depending on the result of os.path.exists(path), to check if the file has been removed.

Is this overkill, have we seen any other edge cases?

@buzinsky
Copy link
Author

buzinsky commented Mar 2, 2020

I agree that all I did was lower the cross section of alerts (I probably should have write this out to save you some time analyzing), and, in principle, this sequence of events causing an error you describe could happen.

My reasoning for sufficiency was that when I do go through slack, the getsize has been the source of all the errors, and none from getctime, so the sequence of events hasn't happened yet.

I think using some sort of wrapper is the better way to do this. I'd rather put this into a separate issue/ future upgrade. Otherwise nothing we do can really be 100% safe. Eg. you could do your isfile(), then dirac deletes it, then we call getsize(), which throws this same error. Very unlikely, and very very tough to completely protect against.

If you see a good reason why you think my change would increase errors from getctime, let me know. I don't think so, but we could add a quick isfile, before doing some wrapping in the longer term

Edit: Hmmm now I want to think about your proposed solution some more.

@buzinsky
Copy link
Author

buzinsky commented Mar 4, 2020

@wcpettus I am confused by this statement:
Should we do something more generic? If we wrap everything starting here:
What do you mean "everything" in this statement? Are you suggesting we just need to wrap the next two lines (51/52) in a try? Or do you want to put the rest of del_dir in a try block? I ask because I didn't think the scoping would work if you just put line 51-end of function in a try block

I do think what you suggest is easy and thorough, however

@wcpettus
Copy link

wcpettus commented Mar 4, 2020

Yes, option 1 that you suggest (we just need to wrap the next two lines (51/52) in a try?)

I think it has the further advantage that the except OSError that you put there could supersede the try/except of lines 40/43. I think it could be extended to have an if os.path.exists(path) then you post a warning, but if the file no longer exists than we understand how we got there and don't even need a warning to go out.

@wcpettus wcpettus closed this Mar 11, 2020
@wcpettus wcpettus reopened this Mar 11, 2020
@wcpettus wcpettus merged commit 11adb23 into develop Mar 11, 2020
@wcpettus wcpettus deleted the feature/dung_getsize branch March 11, 2020 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants