Skip to content

Conversation

@Forgind
Copy link
Contributor

@Forgind Forgind commented Oct 29, 2021

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.

@Forgind Forgind changed the title Attempt to prevent node explosions Attempt to prevent node explosions with parallel node creation Nov 1, 2021
Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

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

I don't think this will solve any current problems but it's conservative so 👍🏻

@Forgind Forgind added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label Nov 8, 2021
@Forgind Forgind merged commit 2b604c3 into dotnet:main Nov 9, 2021
@Forgind Forgind deleted the limit-created-nodes branch November 9, 2021 18:38
benvillalobos pushed a commit to benvillalobos/msbuild that referenced this pull request Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants