Repository navigation
Avoid cachedir races - #3353
Avoid cachedir races#3353
Conversation
Signed-off-by: Mats Wichmann <[email protected]>
| # produce a warning. If the directory doesn't exist or is empty, | ||
| # write a config file. | ||
|
|
||
| from SCons.Util import PY3 |
There was a problem hiding this comment.
Can do. Or could turn into a slightly wonky feature test instead, based on:
Python 2.7.15 (default, Oct 15 2018, 15:26:09)
[GCC 8.2.1 20180801 (Red Hat 8.2.1-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.makedirs("foo", exist_ok=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: makedirs() got an unexpected keyword argument 'exist_ok'
>>>
| # directory) | ||
| if os.path.isdir(path) and len(os.listdir(path)) != 0: | ||
| #if os.path.isdir(path) and len(os.listdir(path)) != 0: | ||
| if os.path.isdir(path) and len([f for f in os.listdir(path) if os.path.basename(f) != "config"]) != 0: |
There was a problem hiding this comment.
Can you get rid of above line, and maybe use Any(os.listdir(path)) ?
There was a problem hiding this comment.
Sure, I can look at that. I just clipped this one from the issue (#3351) so some improvement could happen in the py2.7 case as well.
1. Add a Py3-only version of the cachedir config read, using exclusive open to avoid races. 2. In the Py2-only version, add the hack from issue SCons#3351 to dodge one source of races. Signed-off-by: Mats Wichmann <[email protected]>
Signed-off-by: Mats Wichmann <[email protected]>
Simplify the Py2 check for an existing-but-old cachedir by using any and a generator expression. Move an import to module scope. Signed-off-by: Mats Wichmann <[email protected]>
sider complained about spelling in a comment after I updated the comment so it got to look at those lines as part of the change. Fix those. Signed-off-by: Mats Wichmann <[email protected]>
|
Looks like this might not completely make things thread safe. We just ran into an issue where it appears the cache file is attempted to be read between file creation and the |
|
Thanks for the report! Can you dump this into a new issue? The efforts to eliminate races have been around the cache entries themselves, not around the cache config file - since that is created rarely (only "first-time"), it probably gets into trouble less often. We have recently added some locking around the msvc-config cache, maybe the same would be applicable here. |
|
Issue #4489 opened, let's continue there. |
This is an initial try to experiment with.
Signed-off-by: Mats Wichmann [email protected]
Contributor Checklist:
master/src/CHANGES.txtdirectory (and read theREADME.txtin that directory)