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

Fixes ThreadPool Exhaustion with ProgressListener #1070

Merged

Conversation

TheAngryByrd
Copy link
Member

@TheAngryByrd TheAngryByrd commented Mar 8, 2023

When using FindAllReferences, I noticed it was taking extremely long to get results back. I noticed the logs coming in about every second which gave me a hunch that it might be threadpool exhaustion. I went digging and found a good article for debugging this sort of things.

Using dotnet-stack I was able to trace down the culprit:

Thread (0x19844):
  [Native Frames]
  System.Private.CoreLib.il!System.Threading.WaitHandle.WaitOneNoCheck(int32)
  FSharp.Core!Microsoft.FSharp.Control.AsyncPrimitives+ResultCell`1[System.__Canon].TryWaitForResultSynchronously(class Microsoft.FSharp.Core.FSharpOption`1<int32>)
  FSharp.Core!Microsoft.FSharp.Control.FSharpMailboxProcessor`1[System.__Canon].TryPostAndReply(class Microsoft.FSharp.Core.FSharpFunc`2<class Microsoft.FSharp.Control.FSharpAsyncReplyChannel`1<!!0>,!0>,class Microsoft.FSharp.Core.FSharpOption`1<int32>)
  fsautocomplete!<StartupCode$fsautocomplete>[email protected](class System.Diagnostics.Activity)
  System.Diagnostics.DiagnosticSource.il!System.Diagnostics.SynchronizedList`1[System.__Canon].EnumWithAction(class System.Action`2<!0,class System.Object>,class System.Object)
  System.Diagnostics.DiagnosticSource.il!System.Diagnostics.Activity.Start()
  System.Diagnostics.DiagnosticSource.il!System.Diagnostics.Activity.Create(class System.Diagnostics.ActivitySource,class System.String,value class System.Diagnostics.ActivityKind,class System.String,value class System.Diagnostics.ActivityContext,class System.Collections.Generic.IEnumerable`1<value class System.Collections.Generic.KeyValuePair`2<class System.String,class System.Object>>,class System.Collections.Generic.IEnumerable`1<value class System.Diagnostics.ActivityLink>,value class System.DateTimeOffset,class System.Diagnostics.ActivityTagsCollection,value class System.Diagnostics.ActivitySamplingResult,bool,value class System.Diagnostics.ActivityIdFormat,class System.String)
  System.Diagnostics.DiagnosticSource.il!System.Diagnostics.ActivitySource.CreateActivity(class System.String,value class System.Diagnostics.ActivityKind,value class System.Diagnostics.ActivityContext,class System.String,class System.Collections.Generic.IEnumerable`1<value class System.Collections.Generic.KeyValuePair`2<class System.String,class System.Object>>,class System.Collections.Generic.IEnumerable`1<value class System.Diagnostics.ActivityLink>,value class System.DateTimeOffset,bool,value class System.Diagnostics.ActivityIdFormat)
  FSharp.Compiler.Service!FSharp.Compiler.Diagnostics.Activity.start(class System.String,class System.Collections.Generic.IEnumerable`1<class System.Tuple`2<class System.String,class System.String>>)
  FSharp.Compiler.Service!<StartupCode$FSharp-Compiler-Service>[email protected](class Microsoft.FSharp.Core.Unit)
  FSharp.Compiler.Service!FSharp.Compiler.BuildGraph+Delay@45-2[System.__Canon].Invoke(class Microsoft.FSharp.Core.Unit)
  FSharp.Core!Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke(value class Microsoft.FSharp.Control.AsyncActivation`1<!!0>,!!1,class Microsoft.FSharp.Core.FSharpFunc`2<!!1,class Microsoft.FSharp.Control.FSharpAsync`1<!!0>>)
  FSharp.Core!Microsoft.FSharp.Control.Trampoline.Execute(class Microsoft.FSharp.Core.FSharpFunc`2<class Microsoft.FSharp.Core.Unit,class Microsoft.FSharp.Control.AsyncReturn>)
  FSharp.Core!<StartupCode$FSharp-Core>[email protected](class System.Object)
  System.Private.CoreLib.il!System.Threading.QueueUserWorkItemCallback.Execute()
  System.Private.CoreLib.il!System.Threading.ThreadPoolWorkQueue.Dispatch()
  System.Private.CoreLib.il!System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()

Turns out I shouldn't be using PostAndReply as it blocks threads.

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

Successfully merging this pull request may close these issues.

2 participants