Bug 1800 - Deadlock in system.web.caching.Cache
Summary: Deadlock in system.web.caching.Cache
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Web ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Jérémie Laval
URL:
Depends on: 1815
Blocks:
  Show dependency tree
 
Reported: 2011-10-31 14:22 UTC by kyann
Modified: 2011-11-04 09:04 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Dependency on System.Web (2.45 KB, text/plain)
2011-10-31 14:22 UTC, kyann
Details
Faster way to reproduce the error (1.81 KB, text/plain)
2011-11-01 10:56 UTC, kyann
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description kyann 2011-10-31 14:22:27 UTC
Created attachment 796 [details]
Dependency on System.Web

Hi,

We are having a deadling in System.Web.Caching.Cache

When running multithread access to te cache we sometimes end in all thread lock.

I have attached a program that launch four thread and do random acess to the cache. After a while the program freeze.

I debug using gdb and I end up with :
 - Thread 1 lock in Cache.cs line 185 (cacheLock.EnterUpgradeableReadLock (); in Get function)
 - Thread 2 lock in Cache.cs line 192 (cacheLock.EnterWriteLock (); in Get function)
 - Thread 3 lock in Cache.cs line 168 (cacheLock.EnterWriteLock (); in Add function)
 - Thread 4 lock in Cache.cs line 185 (cacheLock.EnterUpgradeableReadLock (); in Get function)
Comment 1 kyann 2011-10-31 14:28:12 UTC
Full thread dump:

"Threapool monitor" tid=0x0xb5aecb70 this=0x0x56dc8 thread handle 0x40a state :
interrupted state owns ()

"Timer-Scheduler" tid=0x0xb520db70 this=0x0xb4dc8 thread handle 0x40f state : wa
iting on 0x40d : Event  owns ()
  at (wrapper managed-to-native) System.Threading.WaitHandle.WaitOne_internal (S
ystem.Threading.WaitHandle,intptr,int,bool) <0xffffffff>
  at System.Threading.WaitHandle.WaitOne (int,bool) <0x0007f>
  at System.Threading.WaitHandle.WaitOne (int) <0x00018>
  at System.Threading.Timer/Scheduler.SchedulerThread () <0x00b23>
  at System.Threading.Thread.StartUnsafe () <0x00057>
  at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,
intptr,intptr) <0xffffffff>

"Threadpool worker" tid=0x0xb5003b70 this=0x0xb4a80 thread handle 0x412 state :
interrupted state owns ()
  at System.Threading.ReaderWriterLockSlim.TryEnterWriteLock (int) <0x00317>
  at System.Threading.ReaderWriterLockSlim.EnterWriteLock () <0x00013>
  at System.Web.Caching.Cache.Add (string,object,System.Web.Caching.CacheDepende
ncy,System.DateTime,System.TimeSpan,System.Web.Caching.CacheItemPriority,System.
Web.Caching.CacheItemRemovedCallback) <0x00023>
  at TestLockMono.Program.exeCacheStuff (int) <0x0024b>
  at TestLockMono.Program.<Main>b__3 () <0x0000f>
  at System.Threading.Tasks.Task.InnerInvoke () <0x00024>
  at System.Threading.Tasks.Task.ThreadStart () <0x000a4>
  at System.Threading.Tasks.Task.Execute (System.Action`1<System.Threading.Tasks
.Task>) <0x00027>
  at System.Threading.Tasks.TpScheduler.TaskExecuterCallback (object) <0x00047>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (objec
t,intptr,intptr,intptr) <0xffffffff>

"Threadpool worker" tid=0x0xb4efeb70 this=0x0xb4888 thread handle 0x413 state :
interrupted state owns ()
  at System.Threading.ReaderWriterLockSlim.TryEnterWriteLock (int) <0x002b0>
  at System.Threading.ReaderWriterLockSlim.EnterWriteLock () <0x00013>
  at System.Web.Caching.Cache.ExpireItems (object) <0x0005f>
  at System.Threading.Timer/Scheduler.TimerCB (object) <0x0012b>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (objec
t,intptr,intptr,intptr) <0xffffffff>

"<unnamed thread>" tid=0x0xb7719b40 this=0x0x56f18 thread handle 0x403 state : n
ot waiting owns ()
  at System.Threading.ReaderWriterLockSlim.TryEnterWriteLock (int) <0x00315>
  at System.Threading.ReaderWriterLockSlim.EnterWriteLock () <0x00013>
  at System.Web.Caching.Cache.Get (string) <0x00083>
  at TestLockMono.Program.exeCacheStuff (int) <0x0025f>
  at TestLockMono.Program.<Main>b__0 () <0x0000f>
  at System.Threading.Tasks.Task.InnerInvoke () <0x00024>
  at System.Threading.Tasks.Task.ThreadStart () <0x000a4>
  at System.Threading.Tasks.Task.Execute (System.Action`1<System.Threading.Tasks
.Task>) <0x00027>
  at System.Threading.Tasks.SchedulerProxy.ParticipateUntil (System.Threading.Ta
sks.Task) <0x0005b>
  at System.Threading.Tasks.TaskScheduler.ParticipateUntil (System.Threading.Tas
ks.Task) <0x0001b>
  at System.Threading.Tasks.Task.Wait () <0x0003f>
  at TestLockMono.Program.Main (string[]) <0x00207>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr
,intptr,intptr) <0xffffffff>

"Threadpool worker" tid=0x0xb530eb70 this=0x0x56000 thread handle 0x40b state :
interrupted state owns ()
  at System.Threading.ReaderWriterLockSlim.TryEnterWriteLock (int) <0x00315>
  at System.Threading.ReaderWriterLockSlim.EnterWriteLock () <0x00013>
  at System.Web.Caching.Cache.Remove (string,System.Web.Caching.CacheItemRemoved
Reason,bool,bool) <0x00033>
  at System.Web.Caching.Cache.Remove (string) <0x0001b>
  at TestLockMono.Program.exeCacheStuff (int) <0x00277>
  at TestLockMono.Program.<Main>b__1 () <0x0000f>
  at System.Threading.Tasks.Task.InnerInvoke () <0x00024>
  at System.Threading.Tasks.Task.ThreadStart () <0x000a4>
  at System.Threading.Tasks.Task.Execute (System.Action`1<System.Threading.Tasks
.Task>) <0x00027>
  at System.Threading.Tasks.TpScheduler.TaskExecuterCallback (object) <0x00047>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (objec
t,intptr,intptr,intptr) <0xffffffff>

"Threadpool worker" tid=0x0xb5108b70 this=0x0xb4c78 thread handle 0x411 state :
interrupted state owns ()
  at System.Threading.ReaderWriterLockSlim.TryEnterWriteLock (int) <0x0030c>
  at System.Threading.ReaderWriterLockSlim.EnterWriteLock () <0x00013>
  at System.Web.Caching.Cache.Add (string,object,System.Web.Caching.CacheDepende
ncy,System.DateTime,System.TimeSpan,System.Web.Caching.CacheItemPriority,System.
Web.Caching.CacheItemRemovedCallback) <0x00023>
  at TestLockMono.Program.exeCacheStuff (int) <0x0024b>
  at TestLockMono.Program.<Main>b__2 () <0x0000f>
  at System.Threading.Tasks.Task.InnerInvoke () <0x00024>
  at System.Threading.Tasks.Task.ThreadStart () <0x000a4>
  at System.Threading.Tasks.Task.Execute (System.Action`1<System.Threading.Tasks
.Task>) <0x00027>
  at System.Threading.Tasks.TpScheduler.TaskExecuterCallback (object) <0x00047>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (objec
t,intptr,intptr,intptr) <0xffffffff>
Comment 2 kyann 2011-11-01 10:56:25 UTC
Created attachment 799 [details]
Faster way to reproduce the error

Faster way to reproduce the error, we cannot add and get at the same time
Comment 3 kyann 2011-11-01 19:33:18 UTC
This is due to a bug in ReaderWriterLockSlim
Comment 4 Jérémie Laval 2011-11-03 20:22:11 UTC
Could you try running your test case again with current master or mono-2-10? AFAICT, it's not deadlocking anymore for me.
Comment 5 kyann 2011-11-04 09:04:11 UTC
fixed :)

work for me !