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

combats uploader race condition #4

Merged
merged 5 commits into from
Jun 27, 2024

Conversation

craigsteffen
Copy link
Contributor

Putting in a CONDITIONAL wait to combat a race condition in the distributed file system. It first checks to see if the file exists. If it doesn't, it waits .1 seconds, if it still doesn't, it waits 1.0 seconds. Then it raises high holy hell about the file not existing.

So if it does indeed exist, we've only incurred the cost of running a single existence check and an if, so it will only do the wait if it already HAS hit the race condition.

Putting in a CONDITIONAL wait to combat a race condition in the distributed file system.  It first checks to see if the file exists. If it doesn't, it waits .1 seconds, if it still doesn't, it waits 1.0 seconds.  Then it raises high holy hell about the file not existing.  

So if it does indeed exist, we've only incurred the cost of running a single existence check and an if, so it will only do the wait if it already HAS hit the race condition.
doing error reporting correctly via logging.exception (instead of print() )
@asaxton asaxton self-requested a review May 13, 2024 20:20
Proper log message for 0.7.3
if not os.path.exists(file):
time.sleep(1)
if not os.path.exists(file):
logging.exception(f"ERROR! File {file} does not exist for uploader even after a wait!")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use logging.exception when you want to print the stack trace for the exception. Since there is no exception at this point, no need to do this. Additionally we will print the raised exception on line 44 so no need to print it twice, just the raise is good enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@robkooper

I'm trying to parse this out.

I think you're saying that when the checks for the file are exhausted, it's not appropriate to call "logging.exception". But are you saying to leave the "raise ValueError"?

I just want to make sure that if the uploader fails because the file it's been told to upload doesn't exist, then what file it's looking for is explicitly stated and that "does not exist", so that the user knows it's not a network problem or a queue problem or something.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe a point of clarity: The logging.exception() is being called in the try: block that started on line 30. At line 44, no exception as been raised that logging.exception() can use in its massaging.

As a loose rule, logging.exception() should only be called in except: blocks.

The except: block is where the program skips to when an exception is raised and thus there is a traceback availbile that logging.exception() can "read" and populate the logging message with. Notice this is what is happening between line 51 and 56

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@robkooper I used the github interface to apply the patch.

Once I got the file back, I don't think it was right. So I spliced the two trees together the way I think you were thinking, which I agree with; it's much more compact. And I removed the logging.exception but left the raise ValueError.

Let me know if that matches what you were thinking. If you think this looks Ok, we should probably exercise the uploader both normally, without the race condition, and then artificially trip it so that it definitely fires, so to make sure it flows correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@asaxton

Ah, thanks, that helps a lot.

Unfortunately I uploaded a new commit just as you posted that comment. Could you glance at the new commit? The patch tool in github kind of mangled the test loops and the new commit cleans them up.

Also I think I've fixed my original misplaced "except" statement.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Everything looks correct to me.

uploader/uploader.py Outdated Show resolved Hide resolved
craigsteffen and others added 2 commits June 26, 2024 16:06
Replacing tree if ifs (for os.path.exists for the target) with a while(not exists) loop with a counter.  Makes it more flexible and more compact.

Co-authored-by: Rob Kooper <[email protected]>
I don't think the github patch applier got the final version of the
code right.  I think this is what Rob intended with his revised while
loop replacing the couple of ifs I had initially written.
@asaxton asaxton merged commit ad474bf into DARPA-CRITICALMAAS:main Jun 27, 2024
0 of 3 checks passed
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.

3 participants