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

Don't hang builds on BuildManager internal errors #5917

Merged
merged 5 commits into from
Dec 4, 2020

Conversation

ladipro
Copy link
Member

@ladipro ladipro commented Nov 26, 2020

The logic to handle exceptions thrown on logging and communication threads was trying to make the build submission fail with the exception but it didn't always complete it. This manifested as the build hanging, for example when building with MSBUILDNODECONNECTIONTIMEOUT = 0, which is almost guaranteed to throw InternalErrorException in InstantiateNode.

This PR fixes it by making sure that all submissions are completed in OnThreadException. Unlike the original code, proper care is taken to avoid race conditions - i.e. the build result is mutated only if hasn't already been passed to the completion handler.

Fixes #5911

src/Build.UnitTests/BackEnd/BuildManager_Tests.cs Outdated Show resolved Hide resolved
src/Build.UnitTests/BackEnd/BuildManager_Tests.cs Outdated Show resolved Hide resolved
// Attach the exception to this submission if it does not already have an exception associated with it
if (submission.BuildResult?.Exception == null)
if (!submission.IsCompleted && submission.BuildResult != null && submission.BuildResult.Exception == null)
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't submission.BuildResult?.Exception == null mean the same thing as submission.BuildResult != null && submission.BuildResult.Exception == null? SharpLab shows an IL difference but it appears to just not be loading the BuildResult field twice in the ?. version.

Copy link
Member

Choose a reason for hiding this comment

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

If submission.BuildResult is null, submission.BuildResult?.Exception is null; ? is like <thing before> == null ? null : <thing before>.<thing after>.

(I ran this.)

Copy link
Member Author

Choose a reason for hiding this comment

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

With value type fields, one can write something like submission.BuildResult?.SomeFlag == false and this is equivalent to submission.BuildResult != null && submission.BuildResult.SomeFlag == false. But it doesn't work with reference type fields as the type of submission.BuildResult?.Exception is just Exception and if it evaluates to null, you can't tell which of the two is null.

Copy link
Member

Choose a reason for hiding this comment

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

You're right; it's the null-to-bool comparison that saves the former case which doesn't apply here.

@ladipro
Copy link
Member Author

ladipro commented Dec 3, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ladipro
Copy link
Member Author

ladipro commented Dec 4, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Forgind Forgind merged commit 618b66a into dotnet:master Dec 4, 2020
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.

Build hangs with MSBUILDNODECONNECTIONTIMEOUT=0
4 participants