Attempt to prevent node explosions with parallel node creation #7004
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
A long time ago, I was struggling with a bug in which we created thousands of MSBuild nodes.
Looking at our code for creating nodes, we fail early in NodeProviderOutOfProc if (_nodeContexts.Count == ComponentHost.BuildParameters.MaxNodeCount). We have an equivalent check in NodeProviderOutOfProcTaskHost. We don't in NodeProviderInProc, presumably because we shouldn't ever have > 1 in proc node.Actually, I don't think this is true because _nodeContexts aren't shared between providers. That said, rainersigwald pointed out this is still helpful if we parallelize this.
I'm wondering if the explosion might be avertable by changing the == to >=. If we haven't used the in-proc node for whatever reason and we use MaxNodeCount nodes, and then we create an in-proc node, we'd have MaxNodeCount + 1 nodes, and we could spiral out of control because the
==checks would no longer be valid.Changes Made
Switched equality to >= or <= as appropriate.
Testing
None. I'm not exactly sure how to set up a situation in which the in-proc node isn't there until MaxNodeCount has been exhausted, then decides to be used. Could happen also if the in-proc node dies for some reason, but I think that would kill the build.
Notes
Maybe not useful; not sure, but it seemed like an easy and possibly impactful change. Computer deaths can be really frustrating.