Skip to content

OutOfMemory exception on a task not reported for a particular task. #9928

@JanKrivanek

Description

@JanKrivanek

Context

Inspired by: https://stackoverflow.microsoft.com/questions/394371

Experience of having a task experiencing OOM:

Build FAILED.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:19:29.61
MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Text.StringBuilder.ToString()
   at System.IO.StringWriter.ToString()
   at Newtonsoft.Json.Linq.JToken.ToString(Formatting formatting, JsonConverter[] converters)
   at Microsoft.Portal.Framework.ContentPackageGenerator.ContentPackageWriter.WriteDocument[T](PackageEntryPath documentPath, T newDocument, T existingDocument)
   at Microsoft.Portal.Framework.ContentPackageGenerator.ContentPackageWriter.WriteProjectsDocument(EffectiveContentPackageProject projects)
   at Microsoft.Portal.Framework.ContentPackageGenerator.PopulatePackage(ContentPackageWriter contentPackage)
   at Microsoft.Portal.Framework.ContentPackageGenerator.GeneratePackage(IContentStore contentStore, Action`2 logger)
   at Microsoft.Portal.Framework.GenerateContentPackageCore.Generate(ContentPackageGeneratorParameters parameters, Action`2 logger)
   at Microsoft.Portal.Pdc.Core.DxBuild.GenerateContentPackage(DxBuildArgs args, ITaskLoggingHelper loggingHelper, String ContentPackageProjectFileWriterResult)
   at Microsoft.Portal.Pdc.Core.DxBuild.Compile(DxBuildArgs args, ITaskLoggingHelper loggingHelper)
   at Microsoft.Portal.Pdc.Core.DxBuildTask.ExecuteCore()
   at Microsoft.Portal.Framework.PortalTaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

Experience of a task experiencing 'traditional exception':

error MSB4018: The "TaskThatReturnsDictionaryTaskItem" task failed unexpectedly.
This is an unhandled exception from a task -- PLEASE OPEN A BUG AGAINST THE TASK OWNER.
System.Exception: Hello there!
   at Microsoft.Build.Engine.UnitTests.TaskThatReturnsDictionaryTaskItem.Execute() in C:\src\msbuild\src\Build.UnitTests\BackEnd\TaskThatReturnsDictionaryTaskItem.cs:line 24
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() in C:\src\msbuild\src\Build\BackEnd\TaskExecutionHost\TaskExecutionHost.cs:line 561
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() in C:\src\msbuild\src\Build\BackEnd\Components\RequestBuilder\TaskBuilder.cs:line 813
Done executing task "TaskThatReturnsDictionaryTaskItem" -- FAILED.
Done building target "Build" in project "Temporary45a7acefae06435d83657c9bcf06a0df.csproj" -- FAILED.
Done building project "Temporary45a7acefae06435d83657c9bcf06a0df.csproj" -- FAILED.
Build FAILED.

The case 2 is much more informative and actionable

Repro steps

  • Edit TaskThatReturnsDictionaryTaskItem
  • Add throw new Exception("Hello there!"); into the Execute() method
  • Execute/Debug one of the unit tests in TaskExecutionHost_Tests (e.g. TestTaskDictionaryOutputItems)
  • Change the exception in Execution method to OutOfMemoryException
  • Execute the test again and compare log outputs

Details

We handle OOM with special care (see

if (ExceptionHandling.IsCriticalException(ex))
) as it might be dangerous to try to perform some nontrivial processing. Though we should inspect the code and reevaluate - I believe we should be able to log more descritpive error with a low risk (as the mere fact of throwin OOM leads to GC and usually to nontrivial freed-up space)

Metadata

Metadata

Assignees

Labels

Priority:2Work that is important, but not critical for the releasetriaged

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions