dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.23k stars 1.35k forks source link

BinaryTranslator.BinaryWriteTranslator.TranslateDictionary throws InvalidOperationException: Collection was modified #6608

Open tmat opened 3 years ago

tmat commented 3 years ago

Issue Description

Hit by CI: https://dev.azure.com/dnceng/public/_build/results?buildId=1198198&view=logs&jobId=85c53086-d585-50b3-ae0b-d040c710cd82

Stack trace:

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
   at Microsoft.Build.BackEnd.BinaryTranslator.BinaryWriteTranslator.TranslateDictionary[D,T](D& dictionary, ObjectTranslator`1 objectTranslator)
   at Microsoft.Build.BackEnd.TranslatorHelpers.TranslateDictionary[D,T](ITranslator translator, D& dictionary, NodePacketValueFactory`1 valueFactory)
   at Microsoft.Build.Execution.ProjectItemInstance.TaskItem.Microsoft.Build.BackEnd.ITranslatable.Translate(ITranslator translator)
   at Microsoft.Build.BackEnd.TranslatorHelpers.Translate[T](ITranslator translator, T& instance, NodePacketValueFactory`1 valueFactory)
   at Microsoft.Build.BackEnd.TranslatorHelpers.<>c__DisplayClass1_0`1.<AdaptFactory>g__Translate|0(ITranslator translator, T& objectToTranslate)
   at Microsoft.Build.BackEnd.BinaryTranslator.BinaryWriteTranslator.Translate[T](List`1& list, ObjectTranslator`1 objectTranslator)
   at Microsoft.Build.BackEnd.TranslatorHelpers.Translate[T](ITranslator translator, List`1& list, NodePacketValueFactory`1 valueFactory)
   at Microsoft.Build.BackEnd.LogMessagePacket.TranslateTargetFinishedEvent(ITranslator translator, TargetFinishedEventArgs finishedEvent)
   at Microsoft.Build.Shared.LogMessagePacketBase.WriteToStream(ITranslator translator)
   at Microsoft.Build.Shared.LogMessagePacketBase.Translate(ITranslator translator)
   at Microsoft.Build.BackEnd.NodeEndpointOutOfProcBase.RunReadLoop(Stream localReadPipe, Stream localWritePipe, ConcurrentQueue`1 localPacketQueue, AutoResetEvent localPacketAvailable, AutoResetEvent localTerminatePacketPump)

Steps to Reproduce

Expected Behavior

Actual Behavior

Analysis

Versions & Configurations

Attach a binlog

Forgind commented 3 years ago

Small extra information: I think this is the enumeration that's throwing. I don't see how it could modify the collection, but it seems to be where the call stack is pointing.