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

BuildCheck throws exception when enabled in Roslyn Repo #11319

Open
YuliiaKovalova opened this issue Jan 21, 2025 · 0 comments · May be fixed by #11361
Open

BuildCheck throws exception when enabled in Roslyn Repo #11319

YuliiaKovalova opened this issue Jan 21, 2025 · 0 comments · May be fixed by #11361

Comments

@YuliiaKovalova
Copy link
Member

Issue Description

After enabling BuildCheck with default settings on roslyn repo , msbuild breaks with:

025-01-15T12:55:54.7713216Z MSBUILD : error MSB4017: The build stopped unexpectedly because of an unexpected logger failure.
2025-01-15T12:55:54.7714414Z Microsoft.Build.Exceptions.InternalLoggerException: The build stopped unexpectedly because of an unexpected logger failure. ---> System.ArgumentException: Source array was not long enough. Check srcIndex and length, and the array's lower bounds.
2025-01-15T12:55:54.7714904Z    at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
2025-01-15T12:55:54.7715184Z    at System.Collections.Generic.List`1.set_Capacity(Int32 value)
2025-01-15T12:55:54.7715464Z    at System.Collections.Generic.List`1.EnsureCapacity(Int32 min)
2025-01-15T12:55:54.7715779Z    at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
2025-01-15T12:55:54.7716174Z    at Microsoft.Build.Experimental.BuildCheck.Infrastructure.BuildCheckManagerProvider.BuildCheckManager.RemoveCheck(CheckFactoryContext checkToRemove)
2025-01-15T12:55:54.7716640Z    at Microsoft.Build.Experimental.BuildCheck.Infrastructure.BuildCheckManagerProvider.BuildCheckManager.RemoveThrottledChecks(ICheckContext checkContext)
2025-01-15T12:55:54.7717172Z    at Microsoft.Build.Experimental.BuildCheck.Infrastructure.BuildCheckCentralContext.RunRegisteredActions[T](List`1 registeredCallbacks, T checkData, ICheckContext checkContext, Action`4 resultHandler)
2025-01-15T12:55:54.7717710Z    at Microsoft.Build.Experimental.BuildCheck.Infrastructure.BuildEventsProcessor.ProcessTaskFinishedEventArgs(ICheckContext checkContext, TaskFinishedEventArgs taskFinishedEventArgs)
2025-01-15T12:55:54.7718234Z    at Microsoft.Build.Experimental.BuildCheck.Infrastructure.BuildCheckManagerProvider.BuildCheckManager.ProcessTaskFinishedEventArgs(ICheckContext checkContext, TaskFinishedEventArgs taskFinishedEventArgs)
2025-01-15T12:55:54.7718823Z    at Microsoft.Build.Experimental.BuildCheck.Infrastructure.BuildCheckBuildEventHandler.HandleTaskFinishedEvent(TaskFinishedEventArgs eventArgs)
2025-01-15T12:55:54.7719396Z    at Microsoft.Build.Experimental.BuildCheck.Infrastructure.BuildCheckBuildEventHandler.<.ctor>b__5_9(BuildEventArgs e)
2025-01-15T12:55:54.7719933Z    at Microsoft.Build.Experimental.BuildCheck.Infrastructure.BuildCheckBuildEventHandler.HandleBuildEvent(BuildEventArgs e)
2025-01-15T12:55:54.7720433Z    at Microsoft.Build.Experimental.BuildCheck.Infrastructure.BuildCheckConnectorLogger.EventSource_AnyEventRaised(Object sender, BuildEventArgs e)
2025-01-15T12:55:54.7720866Z    at Microsoft.Build.BackEnd.Logging.EventSourceSink.RaiseAnyEvent(Object sender, BuildEventArgs buildEvent)
2025-01-15T12:55:54.7721337Z    --- End of inner exception stack trace ---
2025-01-15T12:55:54.7721741Z    at Microsoft.Build.Exceptions.InternalLoggerException.Throw(Exception innerException, BuildEventArgs e, String messageResourceName, Boolean initializationException, String[] messageArgs)
2025-01-15T12:55:54.7722227Z    at Microsoft.Build.BackEnd.Logging.EventSourceSink.RaiseAnyEvent(Object sender, BuildEventArgs buildEvent)
2025-01-15T12:55:54.7722621Z    at Microsoft.Build.BackEnd.Logging.EventSourceSink.RaiseStatusEvent(Object sender, BuildStatusEventArgs buildEvent)
2025-01-15T12:55:54.7723018Z    at Microsoft.Build.BackEnd.Logging.EventSourceSink.RaiseTaskFinishedEvent(Object sender, TaskFinishedEventArgs buildEvent)
2025-01-15T12:55:54.7723395Z    at Microsoft.Build.BackEnd.Logging.EventSourceSink.Consume(BuildEventArgs buildEvent)
2025-01-15T12:55:54.7723967Z    at Microsoft.Build.BackEnd.Logging.EventSourceSink.Consume(BuildEventArgs buildEvent, Int32 sinkId)
2025-01-15T12:55:54.7724486Z    at Microsoft.Build.BackEnd.Logging.EventRedirectorToSink.Microsoft.Build.Framework.IEventRedirector.ForwardEvent(BuildEventArgs buildEvent)
2025-01-15T12:55:54.7725070Z    at Microsoft.Build.Experimental.BuildCheck.Infrastructure.BuildCheckForwardingLogger.EventSource_AnyEventRaised(Object sender, BuildEventArgs buildEvent)
2025-01-15T12:55:54.7725560Z    at Microsoft.Build.Framework.AnyEventHandler.Invoke(Object sender, BuildEventArgs e)
2025-01-15T12:55:54.7725920Z    at Microsoft.Build.BackEnd.Logging.EventSourceSink.RaiseAnyEvent(Object sender, BuildEventArgs buildEvent)
2025-01-15T12:55:54.9221835Z Build failed with exit code 1. Check errors above.

Steps to Reproduce

Use PR attached above

Expected Behavior

BuildCheck runs as expected.

Actual Behavior

MSbuild Breaks

Analysis

It looks like the environment modifies _checkRegistry concurrently due to throttling logic

foreach (var throttledCheck in _checkRegistry.FindAll(c => c.MaterializedCheck?.IsThrottled ?? false))

and

private void RemoveCheck(CheckFactoryContext checkToRemove)

In RemoveChecksAfterExecutedActions the code is processing throttled checks and RemoveCheck method is modifying the _checkRegistry while the FindAll loop is still iterating over it.

Versions & Configurations

sdk 9.0.100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants