Skip to content
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

MSBuild occasionally succeeds despite /WarnAsError:MSB3270 #5689

Closed
atniomn opened this issue Aug 28, 2020 · 10 comments
Closed

MSBuild occasionally succeeds despite /WarnAsError:MSB3270 #5689

atniomn opened this issue Aug 28, 2020 · 10 comments
Labels
Area: Static Graph Issues with -graph, -isolate, and the related APIs. bug triaged

Comments

@atniomn
Copy link

atniomn commented Aug 28, 2020

Issue Description

When running MSBuild with /WarnAsError:MSB3270, MSBuild will occasionally succeed, despite warnings being promoted into an errors.

I do not observe this behavior with /graph:true

Steps to Reproduce

I notice there are many other issues similar to this one, so I took it upon myself to construct a reliable reproduction of the issue.

WarnAsErrorTest.zip

The code attached contains a really simple C# solution (.NET Framework 4.7.2 console application) which deliberately has misaligned platforms.

I have included a powershell script, test.ps1, which can be run with /graph:false

PS WarnAsErrorTest> .\test.ps1

or with /graph:true

PS WarnAsErrorTest> .\test.ps1 -GraphBuild $true

Expected Behavior

Regardless of whether or not I am using /graph:true, MSBuild should fail in a deterministic manner

Actual Behavior

MSBuild fails most of the time, but occasionally succeeds.

Versions & Configurations

Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

16.6.0.22303

pwsh v7.0.3

I recommend /graph:true to anyone experiencing this problem.
I understand the historic justification for having /graph:false be default, but /graph:true seems much more sane now.

@atniomn atniomn added bug needs-triage Have yet to determine what bucket this goes in. labels Aug 28, 2020
@benvillalobos benvillalobos self-assigned this Sep 2, 2020
@benvillalobos benvillalobos added under-investigation Area: Static Graph Issues with -graph, -isolate, and the related APIs. labels Sep 2, 2020
@benvillalobos
Copy link
Member

Note to self: Might need to lean on Mihai for this one.

@pakrym
Copy link

pakrym commented Jan 5, 2021

Related: #9825

@pakrym
Copy link

pakrym commented Jan 5, 2021

Related: #3295

@atniomn
Copy link
Author

atniomn commented Feb 10, 2021

Related: #4842

@benvillalobos
Copy link
Member

benvillalobos commented May 12, 2021

This was likely resolved by #6174 and I can't repro this on 16.10 msbuild. Are you still seeing this on an updated MSBuild?

To be specific, this should be available in vs16.10 preview 1

@benvillalobos benvillalobos added needs-more-info Issues that need more info to continue investigation. and removed needs-triage Have yet to determine what bucket this goes in. labels May 21, 2021
@benvillalobos
Copy link
Member

Closing this as resolved.

@Forgind
Copy link
Member

Forgind commented Dec 6, 2021

I'm seeing this still in 17.0 with the repro I provided here in at least some cases.

@Forgind Forgind reopened this Dec 6, 2021
@Forgind Forgind removed the needs-more-info Issues that need more info to continue investigation. label Dec 6, 2021
@benvillalobos
Copy link
Member

The reason this was reopened: There seems to be a difference between dotnet build and msbuild when building a project like the one at #7094. dotnet build sees a successful build (despite errors) while msbuild sees the proper build failure.

Versions:
6.0.100/ msbuild 17.0 c9eb9dd(sees repro)
full framework 17.0+ doesn't see the issue.

@benvillalobos
Copy link
Member

Can confirm this still happens.

C:\Users\bevillal\Downloads\Compressed\WarnAsErrorTest\WarnAsErrorTest\TestProj>dotnet build /t:AlwaysRun /WarnAsError:NAT011
MSBuild version 17.4.0-preview-22470-08+6521b1591 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
C:\Users\bevillal\Downloads\Compressed\WarnAsErrorTest\WarnAsErrorTest\TestProj\TestProj.csproj(12,9): error NAT011: You fail
C:\Users\bevillal\Downloads\Compressed\WarnAsErrorTest\WarnAsErrorTest\TestProj\TestProj.csproj(13,9): warning NAT012: Other Fail

Build FAILED.

C:\Users\bevillal\Downloads\Compressed\WarnAsErrorTest\WarnAsErrorTest\TestProj\TestProj.csproj(13,9): warning NAT012: Other Fail
C:\Users\bevillal\Downloads\Compressed\WarnAsErrorTest\WarnAsErrorTest\TestProj\TestProj.csproj(12,9): error NAT011: You fail
    1 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.17

C:\Users\bevillal\Downloads\Compressed\WarnAsErrorTest\WarnAsErrorTest\TestProj>
C:\Users\bevillal\Downloads\Compressed\WarnAsErrorTest\WarnAsErrorTest\TestProj>dotnet build /t:AlwaysRun /WarnAsError:NAT011
MSBuild version 17.4.0-preview-22470-08+6521b1591 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
C:\Users\bevillal\Downloads\Compressed\WarnAsErrorTest\WarnAsErrorTest\TestProj\TestProj.csproj(12,9): error NAT011: You fail
C:\Users\bevillal\Downloads\Compressed\WarnAsErrorTest\WarnAsErrorTest\TestProj\TestProj.csproj(13,9): warning NAT012: Other Fail

Build succeeded.

C:\Users\bevillal\Downloads\Compressed\WarnAsErrorTest\WarnAsErrorTest\TestProj\TestProj.csproj(13,9): warning NAT012: Other Fail
C:\Users\bevillal\Downloads\Compressed\WarnAsErrorTest\WarnAsErrorTest\TestProj\TestProj.csproj(12,9): error NAT011: You fail
    1 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.15

dotnet --version

7.0.100-rc.2.22477.23

Investigation Notes

After quite a bit of digging I don't see anything wrong with the way that the SDK logs the error. It correctly gets all the way to logging an error into the logging service here, which goes into ProcessLoggingEvent where it goes into the queue and I can't track it down anymore.

_taskLoggingContext.LoggingService.LogBuildEvent(e);

It's worth noting that the first warning getting logged (the one that should error) hits line 1191, whereas the second (the one that doesn't fail) hits line 1198. It's worth noting because RouteBuildEvent has logic to properly account for errors.

internal virtual void ProcessLoggingEvent(object buildEvent)
{
ErrorUtilities.VerifyThrow(buildEvent != null, "buildEvent is null");
if (_logMode == LoggerMode.Asynchronous)
{
// Block until queue is not full.
while (_eventQueue.Count >= _queueCapacity)
{
// Block and wait for dequeue event.
_dequeueEvent.Wait();
_dequeueEvent.Reset();
}
_eventQueue.Enqueue(buildEvent);
_enqueueEvent.Set();
}
else
{
lock (_lockObject)
{
RouteBuildEvent(buildEvent);
}
}
}

@benvillalobos benvillalobos removed their assignment Nov 15, 2022
@AR-May
Copy link
Member

AR-May commented Jun 26, 2023

This issue resurfaced again: dotnet/installer#8735
We will close this one as a duplicate in favor to the issue above.
The PR with fix is already attached to the issue above.

@AR-May AR-May closed this as not planned Won't fix, can't repro, duplicate, stale Jun 26, 2023
JaynieBai pushed a commit that referenced this issue Jun 27, 2023
Fixes #8735, possibly #5689, #2845

Context
There were race condition when ProjectFinished log message has been processed after BuildResult event. Even though ProjectFinished log message event is always send before BuildResult event from Node, because ProjectFinished is asyncronously routed by LoggingService reversing order can and do often happen.

Changes Made
Updating _overallBuildSuccess in one place when submission is considered to be done and assumed its final state.

Testing
Can't local repro.
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Static Graph Issues with -graph, -isolate, and the related APIs. bug triaged
Projects
None yet
Development

No branches or pull requests

5 participants