Skip to content

Visual Studio crashes due to TypeScript running out of memory #9417

@Vilx2

Description

@Vilx2

TypeScript Version: 1.8.34.0

Since I updated my Visual Studio 2015 to Update 3 this morning, it has started to crash very often. Basically at least once an hour. It's quite random, and unfortunately I cannot share any code (it happens when working on our commercial product). But I can share a stack trace that I get out of Event Viewer:

Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.OutOfMemoryException
   at Newtonsoft.Json.JsonTextReader.ReadData(Boolean, Int32)
   at Newtonsoft.Json.JsonTextReader.ReadStringIntoBuffer(Char)
   at Newtonsoft.Json.JsonTextReader.ParseString(Char)
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.JsonTextReader.ReadInternal()
   at Newtonsoft.Json.JsonTextReader.Read()
   at Newtonsoft.Json.Linq.JContainer.ReadContentFrom(Newtonsoft.Json.JsonReader)
   at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(Newtonsoft.Json.JsonReader)
   at Newtonsoft.Json.Linq.JObject.Load(Newtonsoft.Json.JsonReader)
   at Newtonsoft.Json.Linq.JToken.ReadFrom(Newtonsoft.Json.JsonReader)
   at Newtonsoft.Json.Linq.JToken.Parse(System.String)
   at Microsoft.CodeAnalysis.Editor.TypeScript.ScriptServices.JsonHelpers.TryGetResult[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.String, System.__Canon ByRef)
   at Microsoft.CodeAnalysis.Editor.TypeScript.ScriptServices.JsonHelpers.ParseEmitOutput(System.String)
   at Microsoft.CodeAnalysis.Editor.TypeScript.ScriptServices.Proxies.LanguageServiceProxy.GetEmitOutput(Microsoft.CodeAnalysis.Editor.TypeScript.Features.ProjectDataCache, Microsoft.CodeAnalysis.Editor.TypeScript.ScriptContexts.ScriptContext, Microsoft.CodeAnalysis.Document, Boolean, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Editor.TypeScript.Features.CompileOnSave.CompileOnSaveHandler+<>c__DisplayClass18_0.<TryEmitAsync>b__0(Microsoft.CodeAnalysis.Editor.TypeScript.ScriptServices.Proxies.LanguageServiceProxy, Microsoft.CodeAnalysis.Editor.TypeScript.Features.ProjectDataCache, Microsoft.CodeAnalysis.Editor.TypeScript.ScriptContexts.ScriptContext)
   at Microsoft.CodeAnalysis.Editor.TypeScript.Features.TaskHandler.ComputeValue[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.String, Microsoft.CodeAnalysis.Editor.TypeScript.ScriptContexts.ScriptContext, Microsoft.CodeAnalysis.Editor.TypeScript.Features.ProjectDataCache, Microsoft.CodeAnalysis.Editor.TypeScript.LanguageServiceOperation`1<System.__Canon>)
   at Microsoft.CodeAnalysis.Editor.TypeScript.Features.TaskHandler+<>c__DisplayClass11_0`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].<PerformOperation>b__0()
   at System.Threading.Tasks.Task`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
   at Microsoft.CodeAnalysis.Editor.TypeScript.Features.TaskHandler+<PerformSemanticFeatureOperationAsync>d__15`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
   at Microsoft.CodeAnalysis.Editor.TypeScript.Features.CompileOnSave.CompileOnSaveHandler+<TryEmitAsync>d__18.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
   at Microsoft.CodeAnalysis.Editor.TypeScript.Features.CompileOnSave.CompileOnSaveHandler+<TryEmitAndSaveOtherDocumentsAsync>d__17.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
   at Microsoft.CodeAnalysis.Editor.TypeScript.Features.CompileOnSave.CompileOnSaveHandler+<ProcessFiles>d__14.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
   at Microsoft.CodeAnalysis.Editor.TypeScript.Features.CompileOnSave.CompileOnSaveHandler+<HandleFileSave>d__13.MoveNext()
   at Microsoft.CodeAnalysis.Editor.TypeScript.Features.CompileOnSave.CompileOnSaveHandler+<HandleFileSave>d__13.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)

From this it is visible that it crashes when doing a Compile-On-Save and that it runs out of address space. I have plenty of physical memory free (several GB), but since Visual Studio is a 32-bit process, it isn't hard to exhaust the address space.

The project is fairly large, but this hasn't happened before, and we haven't added any significant amount of new code lately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions