Bug 29667

Summary: Mono v4.0 crashes after a while
Product: [Mono] Class Libraries Reporter: henrik
Component: GeneralAssignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: major CC: avivi.adi.hr, brett.christensen, miguel, mono-bugs+mono, mono-bugs+runtime
Priority: Normal    
Version: 4.0.0   
Target Milestone: Untriaged   
Hardware: Macintosh   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

Description henrik 2015-05-01 16:18:06 UTC
I'm running a F# web app with Logary and Suave and I just got a crash like this:

System.ArgumentException: Type MemoryCache cannot be marshaled as an unmanaged structure. Parameter name: t
  at at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal:SizeOf (System.Type)
  at System.Runtime.Caching.SRef.get_ApproximateSize () [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.Runtime.Caching/ReferenceSources/SRef.cs:21
  at System.Runtime.Caching.CacheMemoryMonitor.GetCurrentPressure () [0x00050] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/external/referencesource/System.Runtime.Caching/System/Caching/CacheMemoryMonitor.cs:155
  at System.Runtime.Caching.MemoryMonitor.Update () [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/external/referencesource/System.Runtime.Caching/System/Caching/MemoryMonitor.cs:92
  at System.Runtime.Caching.MemoryCacheStatistics.Update () [0x0000b] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/external/referencesource/System.Runtime.Caching/System/Caching/MemoryCacheStatistics.cs:160
  at System.Runtime.Caching.MemoryCacheStatistics.CacheManagerThread (Int32 minPercent) [0x00028] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/external/referencesource/System.Runtime.Caching/System/Caching/MemoryCacheStatistics.cs:209
  at System.Runtime.Caching.MemoryCacheStatistics.CacheManagerTimerCallback (System.Object state) [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/external/referencesource/System.Runtime.Caching/System/Caching/MemoryCacheStatistics.cs:83
  at System.Threading.Timer+Scheduler.TimerCB (System.Object o) [0x00007] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/corlib/System.Threading/Timer.cs:327
Comment 3 henrik 2015-05-07 08:40:06 UTC
F#, OS X here.
Comment 4 henrik 2015-05-08 04:57:06 UTC
Another crash around MemoryCache that brings down the AppDomain + Process

10:48:22 web.1        | Unhandled Exception:
10:48:22 web.1        | System.ObjectDisposedException: The object was used after being disposed.
10:48:22 web.1        |   at System.Threading.WaitHandle.CheckDisposed () [0x00016] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/corlib/System.Threading/WaitHandle.cs:426
10:48:22 web.1        |   at System.Threading.EventWaitHandle.Reset () [0x0000c] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/corlib/System.Threading/EventWaitHandle.cs:196
10:48:22 web.1        |   at (wrapper remoting-invoke-with-check) System.Threading.EventWaitHandle:Reset ()
10:48:22 web.1        |   at System.Runtime.Caching.MemoryCacheStore.BlockInsert () [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/external/referencesource/System.Runtime.Caching/System/Caching/MemoryCacheStore.cs:174
10:48:22 web.1        |   at System.Runtime.Caching.CacheEntryCollection.FlushItems (DateTime limit, CacheEntryRemovedReason reason, Boolean blockInsert, Int32 count) [0x00008] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.Runtime.Caching/ReferenceSources/CacheEntryCollection.cs:65
10:48:22 web.1        |   at System.Runtime.Caching.CacheExpires.FlushExpiredItems (Boolean blockInsert) [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.Runtime.Caching/ReferenceSources/CacheExpires.cs:78
10:48:22 web.1        |   at System.Runtime.Caching.CacheExpires.<EnableExpirationTimer>m__0 (System.Object o) [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.Runtime.Caching/ReferenceSources/CacheExpires.cs:69
10:48:22 web.1        |   at System.Threading.Timer+Scheduler.TimerCB (System.Object o) [0x00007] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/corlib/System.Threading/Timer.cs:327
10:48:22 web.1        | exited with code 255
Comment 5 henrik 2015-05-08 05:03:49 UTC
Mono JIT compiler version 4.0.0 ((detached/d136b79 Mon Apr 13 14:40:59 EDT 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  x86
	Disabled:      none
	Misc:          softdebug
	LLVM:          yes(3.6.0svn-mono-(detached/a173357)
	GC:            sgen
Comment 6 brett.christensen 2015-05-08 20:34:59 UTC
I've had the same using the official docker mono 4.0 image
Comment 7 Marek Safar 2015-05-09 06:26:53 UTC
Fixed in master
Comment 8 Miguel de Icaza [MSFT] 2015-05-09 09:48:48 UTC
Guys, 

Could you apply this patch to your Mono 4.0.0 and try if this fixes the issue for you?

https://github.com/mono/mono/commit/ffb5c90e08d2f619b207c07c25b8551f52e9913e
Comment 9 Adi 2015-05-11 04:37:27 UTC
Solves the problem :)