-
-
Notifications
You must be signed in to change notification settings - Fork 320
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
Construction of DefaultEnvironment can be racy #4426
Comments
I guess I don't see how this can happen. Aren't all calls to DefaultEnvironment() in the Sconstruct/SConscripts? They's not in the DAG walk/build right? |
Calls can be triggered internally, when code that wants a bit of context finds it doesn't have enough (should that ever happen?), although I haven't searched in detail what implications all of these have. For example, the |
In particular, it seems this is a likely culprit - a method of any environment: def get_CacheDir(self):
try:
path = self._CacheDir_path
except AttributeError:
path = SCons.Defaults.DefaultEnvironment()._CacheDir_path The referenced PR proposed wrapping the Would actually prefer not to go down the path of instantiating the default environment here at all, but I guess that's the place the value of a bare |
Yes. This is very odd. Maybe we can get the #4424 author to instrument his scons to dump stack traces of DefaultEnvironment() calls ? |
This captures a discussion from #4424
The global function
DefaultEnvironment
is a factory function that returns the default environment object (effectively a singleton) which is a special environment instance. As an additional quirk, the factory then replaces itself with another function which just immediately returns the object, so once the singleton is fully initialized, it is very fast and very safe. However, the actual creation can potentially be quite slow:If nothing particular has been said in a project's SConscripts, the call to
Environment()
(which will be assigned to_default_env
) needs not only to create and initialize the instance, but go through the whole tool setup process, which can include calls to external commands to ask them about versions and/or setup information. Thus, it is possible that in a multithreaded build, a second event could require theDefaultEnvironment
, call the factory, end up in the initial version because the overwrite has not happened yet, see_default_env
is not yet set because the first instance is still working, and proceed to try to create another instance.Any problems can be mitigated by explicitly calling
DefaultEnvironment(tools=[])
(which many SCons tests do, for performance reasons), which greatly reduces the timing window, and also forces the creation to happen early and not in the multithreaded build phase. However, asking users to put in a dummy call for purposes that are not visible (i.e. "help avoid an internal error") seems like an unreasonable burden.The text was updated successfully, but these errors were encountered: