Skip to content

Conversation

@YuliiaKovalova
Copy link
Member

Fixes #9322

Context

In an attempt to build an invalid project with MSBUILDNOINPROCNODE=1, the exception "Out of boundary" was thrown.

Changes Made

Add a check before accessing the array element by index.

Testing

UTs are added

Copy link
Member

@ladipro ladipro 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 fix is addressing the root cause of the issue. It rather hides it by suppressing the live output.

The crash is caused by the fact that single-process build passes 1 as nodeCount to the logger's Initialize method, but the out-of-proc node created with MSBUILDNOINPROCNODE=1 has NodeId of 2.

It may be reasonable to simply use nodeIndex = Math.Min(nodeIndex, _nodes.Length - 1) but we should be sure that it only kicks in in this scenario, i.e. that we don't end up with two nodes using the same _nodes slot. Another safe option would be to create the _nodes array one bigger than what's indicated by nodeCount.

To see why the current fix does not fully work, please try a long-running build with MSBUILDNOINPROCNODE=1 and see if live output is working.

@ladipro
Copy link
Member

ladipro commented Nov 2, 2023

Another option: Make _nodes a List<NodeStatus> and resize to accommodate the highest node ID seen. That would break the reliance of internal node numbering with no/negligible perf impact.

@YuliiaKovalova
Copy link
Member Author

I don't think this fix is addressing the root cause of the issue. It rather hides it by suppressing the live output.

The crash is caused by the fact that single-process build passes 1 as nodeCount to the logger's Initialize method, but the out-of-proc node created with MSBUILDNOINPROCNODE=1 has NodeId of 2.

It may be reasonable to simply use nodeIndex = Math.Min(nodeIndex, _nodes.Length - 1) but we should be sure that it only kicks in in this scenario, i.e. that we don't end up with two nodes using the same _nodes slot. Another safe option would be to create the _nodes array one bigger than what's indicated by nodeCount.

To see why the current fix does not fully work, please try a long-running build with MSBUILDNOINPROCNODE=1 and see if live output is working.

Oh, I see! thank you for letting me know.

Copy link
Member

@ladipro ladipro left a comment

Choose a reason for hiding this comment

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

Looks good to me, thank you.

Co-authored-by: Ladi Prosek <[email protected]>
@YuliiaKovalova YuliiaKovalova changed the title Fix TL failure of invalid project input Fix TL failure on MSBUILDNOINPROCNODE env variable Nov 6, 2023
@YuliiaKovalova YuliiaKovalova merged commit f52cd02 into dotnet:main Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Terminal logger crashes in TargetStarted coming from OOP node

3 participants