Uh oh!
There was an error while loading. Please reload this page.
avoid race condition during chunk write - #327
Conversation
| # On windows, rename() can't overwrite files. So | ||
| # the file is removed first. | ||
| os.remove(new) | ||
| os.rename(old, new) |
There was a problem hiding this comment.
So this is the case where we would want the pyosreplace package. It's a Windows only backport for os.replace on Python 2.
alimanfoo
commented
Nov 9, 2018
Just to mention that there are some potential consequences from implementing this PR that we should be aware of, described in #328. I don't think that should stop us from moving ahead with this PR, using os.replace() is clearly a better thing to do under any circumstances, but just something to be aware of. |
@jakirkham I've made a guess at the |
Uh oh!
There was an error while loading. Please reload this page.
jakirkham
commented
Nov 16, 2018
Think you had it basically right. Unfortunately there is some lack of clarity about when a colon or semicolon should be used. IIUC it should be a semicolon. |
jakirkham
left a comment
There was a problem hiding this comment.
LGTM. Thanks for working on this @sbalmer.
Hopefully the comment above is useful. Am personally fine with how this is. Though if you want to use environment markers instead (or others prefer this), that could be also done, but don't personally think this is critical.
alimanfoo
commented
Nov 20, 2018
Thanks @sbalmer. Could you add pyosreplace to requirements.txt and requirements_dev.txt, pinned to the latest version in the latter. I guess environment markers are needed in both. |
When the chunk file is first removed before the new version is moved into place, racing reads may encounter a missing chunk. Using rename() or replace() without remove() avoids the issue on Posix-Systems as the methods are atomic. The fallback of remove() -> rename() is included for Windows pre Python 3.3. Fixeszarr-developers#263
so it's not repeated on every write
Because the env markers didn't work. Just guessing at this point.
sbalmer
commented
Nov 21, 2018
@alimanfoo |
jakirkham
commented
Nov 26, 2018
Thanks @sbalmer. LGTM. 😄 Let's see what @alimanfoo thinks. 😉 |
jakirkham
commented
Dec 4, 2018
I wonder if we can just drop the |
alimanfoo
commented
Dec 4, 2018
FWIW I imagine it could still be possible that some failure occurs during the attempt to write to the temporary file (e.g., device gets full or something like that), in which case an exception occurs before the value has been fully written, in which case we'd still want to clean up the temporary file. |
jakirkham
commented
Dec 4, 2018
Good point. |
alimanfoo
commented
Dec 4, 2018
I've resolved conflicts after merging #352 and added a release note. Will merge if CI passes. |
alimanfoo
commented
Dec 4, 2018
@sbalmer apologies I didn't know your full name to include in the release note, you're credited currently just as "sbalmer", happy to leave it that way or add your full name, whichever you prefer. |
jakirkham
commented
Dec 5, 2018
Thanks @sbalmer 😄 |
sbalmer
commented
Dec 6, 2018
Thanks @alimanfoo, @jakirkham! Now we can use mainline again :-) |
When the chunk file is first removed before the new version
is moved into place, racing reads may encounter a missing chunk.
Using rename() or replace() without remove() avoids the issue
on Posix-Systems as the methods are atomic. The fallback of
remove() -> rename() is included for Windows pre Python 3.3.
Fixes#263
TODO:
tox -e docs)