question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Threads stuck in Monitor.Wait in ContentFactory.InitField()

See original GitHub issue

Hi Hakan,

I have another (hopefully) quick question for you.

Occasionally in our production environment (hosted as an Azure App Service), the Thread Count jumps up quite dramatically on one of the instances and it becomes completely unresponsive until I go in and restart it manually.

The application itself gets about 4-10k vistors a day.

I am running 8.0.0 and I have MemoryCache enabled and switched up to Full.

I was able to take a memory dump during one of these episodes and I found that quite a lot of these threads were hung up in Piranha.Services.ContentFactory.InitField(). Here is the Call stack of these threads starting from our controller up to where the thread seems to get locked.

System.Threading.ManualResetEventSlim.Wait(Int32, System.Threading.CancellationToken)+22d
--
System.Threading.Tasks.Task.SpinThenBlockingWait(Int32, System.Threading.CancellationToken)+92
System.Threading.Tasks.Task.InternalWaitCore(Int32, System.Threading.CancellationToken)+f1
System.Threading.Tasks.Task.Wait(Int32, System.Threading.CancellationToken)+35
Piranha.Services.ContentFactory.InitField(Microsoft.Extensions.DependencyInjection.IServiceScope, System.Object)+14e
Piranha.Services.ContentFactory.InitRegion(Microsoft.Extensions.DependencyInjection.IServiceScope, System.Object, Piranha.Models.RegionType)+bb
Piranha.Services.ContentFactory.Init[[System.__Canon, System.Private.CoreLib]](System.__Canon, Piranha.Models.ContentType)+c8
Piranha.Services.PageService+d__18`1[[System.__Canon, System.Private.CoreLib]].MoveNext()+13f
System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Piranha.Services.PageService+d__18`1[[System.__Canon, System.Private.CoreLib]], Piranha]](d__18`1 ByRef)+5e
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, System.Private.CoreLib]].Start[[Piranha.Services.PageService+d__18`1[[System.__Canon, System.Private.CoreLib]], Piranha]](d__18`1 ByRef)+2d
Piranha.Services.PageService.GetByIdAsync[[System.__Canon, System.Private.CoreLib]](System.Guid)+66
DigiBook.Controllers.HomeController+d__6.MoveNext()+74
System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[DigiBook.Controllers.HomeController+d__6, DigiBook]](d__6 ByRef)+43
--
DigiBook.Controllers.HomeController.DefaultHomepageAsync(System.Guid, Boolean)+3c

I had a look in the InitField Function and can see the following line is performing a Wait() on the task. Is this something you think could potentially cause Deadlock?

Task.Run(async () => await ((Task)init.Invoke(field, param.ToArray())).ConfigureAwait(false)).Wait();

I have to say, I am in no means an expert on these things and have been learning as much as I can over the last few weeks. I am just trying to get to the bottom of this issue as it’s worrisome that it happens for no reason.

I can provide you with more information if required.

Many Thanks

Adam

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:27 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
tidyuicommented, Feb 17, 2020

Piranha.Data.EF.SQLServer 8.1.1 should be available on NuGet now.

1reaction
tidyuicommented, Feb 12, 2020

I have merged the code into master and updated project & nuspec versions to 8.1.0-beta4 which is our internal pre-release number. You can build the packages locally by:

  1. Pull the latest source code
  2. Run npm-install in core/Piranha.Manager from the command line
  3. Run ./pack.sh in the root directory from the command line

This will give you all of the packages in an artifacts folder in the project root.

Please note that there will be some differences you’ll have to make, for example you’ll have to include a database-provider package due to changes in EF Core Migrations >= 3.0. Take a look at the examples in the repository for guidance.

Best regards

Read more comments on GitHub >

github_iconTop Results From Across the Web

Threading problem with Monitor.Wait() and Monitor.Pulse()
Inside Mediator I use this.Pulse() every time something is Enqueued or Dequeued so waiting threads would be signaled and continue their work.
Read more >
Monitor.Wait Method (System.Threading)
The thread that invokes Wait is later interrupted from the waiting state. This happens when another thread calls this thread's Interrupt() method.
Read more >
Monitor.Pulse(Object) Method (System.Threading)
Notifies a thread in the waiting queue of a change in the locked object's state.
Read more >
A lock is held during a wait - CodeQL - GitHub
Wait() can lead to performance problems or deadlock because the lock can prevent other threads from running. This can be caused by nesting...
Read more >
Monitor madness, part one
“wait” causes the monitor to exit and puts the current thread to sleep. More specifically, it causes a thread to enter the “wait...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found