<div dir="ltr">Hello Mikhail,<div><br></div><div>Please file a bug report so we can properly track this issue.</div><div><br></div><div><a href="http://bugzilla.xamarin.com">http://bugzilla.xamarin.com</a></div><div><br></div><div>Miguel</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 16, 2016 at 5:04 AM, Mikhail Filippov <span dir="ltr"><<a href="mailto:mikhail@filippov.me" target="_blank">mikhail@filippov.me</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I found problem in Mono in named mutex I have repro program:<br>
using System;<br>
using System.Threading;<br>
<br>
namespace Crasher<br>
{<br>
        internal class Program<br>
        {<br>
                public static void Main (string[] args)<br>
                {<br>
                        var a = "";<br>
                        for (var i = 0; i < 100; i++)<br>
                        {<br>
                                new Thread(Crasher).Start();<br>
                        }<br>
                        Console.WriteLine(a);<br>
                        Console.ReadLine();<br>
                }<br>
<br>
                private static void Crasher(){<br>
                        var rnd = new Random();<br>
                        while (true)<br>
                        {<br>
                                Thread.Sleep(rnd.Next(100, 10000));<br>
                                using (var mutex = new Mutex(false, "Global\\TEST"))<br>
                                {<br>
                                        var owner = false;<br>
                                        try<br>
                                        {<br>
                                                owner = mutex.WaitOne(TimeSpan.FromMinutes(1));<br>
                                        }<br>
                                        finally<br>
                                        {<br>
                                                if (owner)<br>
                                                {<br>
                                                        mutex.ReleaseMutex();<br>
                                                }<br>
                                        }<br>
                                        Console.WriteLine ("PING");<br>
                                }<br>
                                Thread.Sleep(rnd.Next(100, 10000));<br>
                        }<br>
                }<br>
        }<br>
}<br>
<br>
It program crached mono after few seconds.<br>
I see namedmutex_create and namedmutex_release use different locks.<br>
First time I found it problem when run Nuget client on mono.<br>
I verify repro on mono 4.2, 4.4, and master.<br>
Anybody can help me resolve this issue?<br>
On 4.4.0 native crash:<br>
namedmutex_create: error creating mutex handle<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
_wapi_handle_unref_full: Attempting to unref unused handle 0x4e0<br>
PING<br>
PING<br>
namedmutex_create: error creating mutex handle<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
_wapi_handle_ref: Attempting to ref unused handle 0x4e3<br>
* Assertion at ../../mono/utils/mono-os-mutex.h:135, condition `res != EINVAL' not met<br>
<br>
Stacktrace:<br>
<br>
  at <unknown> <0xffffffff><br>
  at (wrapper managed-to-native) System.Threading.WaitHandle.WaitOne_internal (System.Threading.WaitHandle,intptr,int,bool) <0x00073><br>
  at System.Threading.WaitHandle.WaitOne (System.TimeSpan,bool) <0x0009b><br>
  at System.Threading.WaitHandle.WaitOne (System.TimeSpan) <0x0001d><br>
  at Crasher.Program.Crasher () <0x000f0><br>
  at System.Threading.ThreadHelper.ThreadStart_Context (object) <0x0009a><br>
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) <0x001c6><br>
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) <0x00020><br>
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object) <0x00059><br>
  at System.Threading.ThreadHelper.ThreadStart () <0x0002e><br>
  at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) <0x000e0><br>
<br>
Native stacktrace:<br>
<br>
        0   mono                                0x0000000103f9b0ca mono_handle_native_sigsegv + 271<br>
        1   libsystem_platform.dylib            0x00007fff854c252a _sigtramp + 26<br>
        2   mono                                0x00000001042036a4 tmp_dir + 5316<br>
        3   libsystem_c.dylib                   0x00007fff935536e7 abort + 129<br>
        4   mono                                0x000000010410d1f0 monoeg_g_log + 0<br>
        5   mono                                0x000000010410d175 monoeg_g_logv + 83<br>
        6   mono                                0x000000010410d31a monoeg_assertion_message + 143<br>
        7   mono                                0x00000001040e453d _wapi_handle_timedwait_signal_handle + 1153<br>
        8   mono                                0x00000001040f4aec wapi_WaitForSingleObjectEx + 606<br>
        9   mono                                0x000000010406c01c mono_wait_uninterrupted + 130<br>
        10  mono                                0x000000010406c1ff ves_icall_System_Threading_WaitHandle_WaitOne_internal + 73<br>
        11  ???                                 0x0000000108130b54 0x0 + 4430433108<br>
        12  mscorlib.dll.dylib                  0x00000001062ed7ae System_Threading_WaitHandle_WaitOne_System_TimeSpan + 30<br>
        13  mscorlib.dll.dylib                  0x0000000106140e5b System_Threading_ThreadHelper_ThreadStart_Context_object + 155<br>
        14  mscorlib.dll.dylib                  0x000000010613f331 System_Threading_ExecutionContext_Run_System_Threading_ExecutionContext_System_Threading_ContextCallback_object_bool + 33<br>
        15  mono                                0x0000000103f04876 mono_jit_runtime_invoke + 1578<br>
        16  mono                                0x0000000104090c23 mono_runtime_invoke + 130<br>
        17  mono                                0x0000000104070409 start_wrapper + 424<br>
        18  mono                                0x0000000104106cb1 inner_start_thread + 305<br>
        19  libsystem_pthread.dylib             0x00007fff989c399d _pthread_body + 131<br>
        20  libsystem_pthread.dylib             0x00007fff989c391a _pthread_body + 0<br>
        21  libsystem_pthread.dylib             0x00007fff989c1351 thread_start + 13<br>
<br>
<br>
<br>
On master UnhandlerException:<br>
namedmutex_create: error creating mutex handle<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
_wapi_handle_unref_full: Attempting to unref unused handle 0x4eb<br>
PING<br>
PING<br>
PING<br>
_wapi_handle_unref_full: Attempting to unref unused handle 0x4ec<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
_wapi_handle_unref_full: Attempting to unref unused handle 0x4ee<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
_wapi_handle_unref_full: Attempting to unref unused handle 0x4f1<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
PING<br>
<br>
Unhandled Exception:<br>
System.ApplicationException: Mutex is not owned<br>
  at System.Threading.Mutex.ReleaseMutex () <0x10e769ef0 + 0x00043> in <filename unknown>:0<br>
  at (wrapper remoting-invoke-with-check) System.Threading.Mutex:ReleaseMutex ()<br>
  at Crasher.Program.Crasher () <0x10cfdfc80 + 0x00129> in <filename unknown>:0<br>
  at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) <0x10e5fb710 + 0x00096> in <filename unknown>:0<br>
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) <0x10e5f93b0 + 0x001c6> in <filename unknown>:0<br>
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) <0x10e5f9380 + 0x00020> in <filename unknown>:0<br>
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) <0x10e5f92d0 + 0x00059> in <filename unknown>:0<br>
  at System.Threading.ThreadHelper.ThreadStart () <0x10e5fb8c0 + 0x0002e> in <filename unknown>:0<br>
_wapi_handle_unref_full: Attempting to unref unused handle 0x4f1<br>
[ERROR] FATAL UNHANDLED EXCEPTION: Nested exception trying to figure out what went wrong<br>
_______________________________________________<br>
Mono-devel-list mailing list<br>
<a href="mailto:Mono-devel-list@lists.ximian.com">Mono-devel-list@lists.ximian.com</a><br>
<a href="http://lists.ximian.com/mailman/listinfo/mono-devel-list" rel="noreferrer" target="_blank">http://lists.ximian.com/mailman/listinfo/mono-devel-list</a><br>
</blockquote></div><br></div>