roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

Out of memory exception when loading a solution (in v0.7.0 it worked).

Open xprzemekw opened this issue 11 years ago • 6 comments

I have a quite large solution which I automatically refactor using roslyn to migrate ASMX Web Services to WCF. Till now I did it using version 0.7.0 of ROslyn, now I switched to 1.0.0-rc2 and solution stopped loading, OpenSolutionAsync ends with OutOfMemoryException after consuming 1.63GB. On v0.7.0 solution loads eating ~74MB. Something went terribly wrong between releases.

Call Stack is as follows:

System.AggregateException: One or more errors occurred. ---> System.OutOfMemoryException: Insufficient memory to continue the execution of the program. at System.Runtime.InteropServices.Marshal.AllocHGlobal(IntPtr cb) at System.Reflection.Internal.StreamMemoryBlockProvider.ReadMemoryBlockNoLock(Stream stream, Boolean isFileStream, Int64 start, Int32 size) at System.Reflection.PortableExecutable.PEReader..ctor(Stream peStream, PEStreamOptions options, Nullable1 sizeOpt) at Microsoft.CodeAnalysis.ModuleMetadata.CreateFromStream(Stream peStream, PEStreamOptions options) at Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(String path, MetadataReferenceProperties properties, DocumentationProvider documentation) at Microsoft.CodeAnalysis.Host.MetadataServiceFactory.Provider.GetReference(String resolvedPath, MetadataReferenceProperties properties) at Microsoft.CodeAnalysis.AssemblyReferenceResolver.ResolveReference(String reference, String baseFilePath, MetadataReferenceProperties properties) at Microsoft.CodeAnalysis.CommandLineArguments.ResolveMetadataReference(CommandLineReference cmdReference, MetadataReferenceResolver metadataResolver, List1 diagnosticsOpt, CommonMessageProvider messageProviderOpt) at Microsoft.CodeAnalysis.CommandLineArguments.ResolveMetadataReferences(MetadataReferenceResolver metadataResolver, List1 diagnosticsOpt, CommonMessageProvider messageProviderOpt, List1 resolved) at Microsoft.CodeAnalysis.CommandLineArguments.ResolveMetadataReferences(MetadataReferenceResolver metadataResolver) at Microsoft.CodeAnalysis.CSharp.CSharpProjectFileLoader.CSharpProjectFile.GetReferences(CSharpCompilerInputs compilerInputs, ProjectInstance executedProject, IEnumerable1& metadataReferences, IEnumerable1& analyzerReferences) at Microsoft.CodeAnalysis.CSharp.CSharpProjectFileLoader.CSharpProjectFile.CreateProjectFileInfo(CSharpCompilerInputs compilerInputs, ProjectInstance executedProject) at Microsoft.CodeAnalysis.CSharp.CSharpProjectFileLoader.CSharpProjectFile.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.d__40.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.d__39.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.d__34.MoveNext() --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task1.get_Result()

xprzemekw avatar May 26 '15 10:05 xprzemekw

@jasonmalinowski @mattwar Did one of you recently look at a leak in MSBuildWorkspace?

Pilchie avatar May 26 '15 21:05 Pilchie

I didn't. @xprzemekw, when it crashes, are you able to make a full memory dump of the process at that point? Then we could take a look at what's causing the leak if you have somewhere to upload it. But it'll be a ~2.0 GB file so if that's unworkable or a huge pain then that's fine.

jasonmalinowski avatar May 26 '15 21:05 jasonmalinowski

@jasonmalinowski I have created a dump and 7zipped it, it is avilable here: https://github.com/xprzemekw/misc/blob/master/MemoryDump.7z

BTW: In 64bits world processing completes eating ~3.2GB.

xprzemekw avatar May 27 '15 09:05 xprzemekw

So this doesn't look like a leak of any MSBuild structures itself -- I see lots of objects in memory but most of them are unrooted. @xprzemekw's stack though might actually be pointing to the problem instead of an unlucky victim though: there's several thousand ModuleMetadatas in memory. Assuming your solution isn't referencing 2000 unique DLLs (seems unlikely :smile:), there must be some broken cache somewhere.

jasonmalinowski avatar May 27 '15 18:05 jasonmalinowski

@Pilchie, it looks like we need a cache here. Quickly adding one wouldn't be too terribly difficult. Want to reconsider the milestone?

jasonmalinowski avatar May 27 '15 19:05 jasonmalinowski

I was able to build an app that opens Roslyn.sln using MSBuildWorkspace and get diagnostics on every project in the solution, and memory stayed around 1GB.

Pilchie avatar Jun 11 '15 17:06 Pilchie