Skip to content

Make DirectoryStore __setitem__ resilient against antivirus file locking #698

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

Merged
merged 17 commits into from
Mar 5, 2021

Conversation

ericgyounkin
Copy link
Contributor

See #597

Enterprise and government computers generally have always-on realtime file scanning antivirus software that causes problems with any system that relies on creation/deletion of lots of small files. We have seen this with SQLite as well, with the temp files it uses. The fix I'm proposing here is to simply try a few times and wait inbetween tries for the antivirus software to release the file lock. I've been running with this fix for a while, and I can now use Zarr on government machines. Hugely helpful. I've seen PermissionErrors floating around the gitter chat and in stackoverflow, so I think this fix is needed for others as well.

The 0.1 sec delay was empirically determined, I've found that the vast majority of writes that generate a PermissionError on the first attempt will work on the second.

Not sure how to build a test for this.

TODO:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/tutorial.rst
  • Changes documented in docs/release.rst
  • AppVeyor and Travis CI passes
  • Test coverage is 100% (Coveralls passes)

@codecov
Copy link

codecov bot commented Feb 10, 2021

Codecov Report

Merging #698 (d42a564) into master (a4fc2c1) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #698   +/-   ##
=======================================
  Coverage   99.94%   99.94%           
=======================================
  Files          28       28           
  Lines       10237    10266   +29     
=======================================
+ Hits        10231    10260   +29     
  Misses          6        6           
Impacted Files Coverage Δ
zarr/storage.py 100.00% <100.00%> (ø)
zarr/tests/test_util.py 100.00% <100.00%> (ø)
zarr/util.py 100.00% <100.00%> (ø)

@pep8speaks
Copy link

pep8speaks commented Feb 10, 2021

Hello @ericgyounkin! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-03-04 13:14:43 UTC

@ericgyounkin
Copy link
Contributor Author

Not sure about these meta.py Linting error messages in Linux Testing / build (3.8). Am I missing something?

@joshmoore
Copy link
Member

joshmoore commented Feb 11, 2021

regarding adding a test, perhaps something like:

joshmoore@3ecee99 ?

@joshmoore
Copy link
Member

These errors others have seen:

zarr/meta.py:82: error: Incompatible return value type (got "List[Union[Tuple[str, str], Tuple[str, str, Tuple[int, ...]]]]", expected "str")
zarr/meta.py:183: error: "generic" has no attribute "real"
zarr/meta.py:184: error: "generic" has no attribute "imag"

so not related to your PR. @Carreau have you seen these elsewhere?

@ericgyounkin
Copy link
Contributor Author

@joshmoore Thats great, thanks! I hadn't seen pytest raises used before, so that makes a lot of sense. How would I use your commit in my PR?

@ericgyounkin
Copy link
Contributor Author

Ignore last comment, pulled from @joshmoore commit and updated PR

@ericgyounkin
Copy link
Contributor Author

@joshmoore I'm a little confused about the status of this pull request, is there anything I should do further? I see that these checks now pass after your changes. Thanks for your work on this.

@joshmoore
Copy link
Member

Hey @ericgyounkin. Apologies. I think I pushed the last commit with my fingers crossed and then moved on to something else while waiting on the tests to go green. Let me merge in master and make sure everything is green, but I assume there's nothing else from your side. Thanks for hanging in there!

@ericgyounkin
Copy link
Contributor Author

Thanks @joshmoore! Do you know how the release schedule works? When the next release is planned? Just planning for the future of my app.

@joshmoore
Copy link
Member

Trying again to get things green after #705.

zarr/storage.py Outdated
# move temporary file into place;
# make several attempts at writing the temporary file to get past
# potential antivirus file locking issues
retry_call(os.replace, (temp_path, file_path))
Copy link
Member

Choose a reason for hiding this comment

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

@ericgyounkin : just realizing (since I have never been able to test this in anger) doesn't PermissionError need listing here? Otherwise, no exceptions are going to be caught.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joshmoore Yes, my mistake. Just added it.

Copy link
Member

@joshmoore joshmoore left a comment

Choose a reason for hiding this comment

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

It's a bit disingenuous for me to review this considering I submitted the function that's being used, but at least there have been two sets of eyes on it. If anyone has issues with the method signature, there's still some time to clean it up before the release of 2.7.0. Otherwise, we'll see how this fairs in the wild.

@joshmoore joshmoore merged commit 946ed95 into zarr-developers:master Mar 5, 2021
@joshmoore
Copy link
Member

Thanks for hanging in there, @ericgyounkin!

@ericgyounkin
Copy link
Contributor Author

@joshmoore Thank you for all your work, big Zarr fan!

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