Bug in ExecuteSynchronizedCore on Linux/MacOS + Mono #2860

Closed
AndreyAkinshin opened this Issue May 30, 2016 · 5 comments

Comments

Projects
None yet
5 participants
@AndreyAkinshin

Hi, I have the following exception:

at <unknown> <0xffffffff>
at (wrapper managed-to-native) System.Threading.WaitHandle.WaitOne_internal (System.Threading.WaitHandle,intptr,int,bool) <0xffffffff>
at System.Threading.WaitHandle.WaitOne (System.TimeSpan,bool) <0x0009b>
at System.Threading.WaitHandle.WaitOne (System.TimeSpan) <0x0001d>
at NuGet.Configuration.Settings.ExecuteSynchronizedCore (System.Action) <0x00143>
at NuGet.Configuration.Settings.ExecuteSynchronized (System.Action) <0x00019>
at NuGet.Configuration.Settings..ctor (string,string,bool) <0x0032b>
at NuGet.Configuration.Settings.ReadSettings (string,string,bool) <0x0008a>
at NuGet.Configuration.Settings.LoadUserSpecificSettings (System.Collections.Generic.List`1<NuGet.Configuration.Settings>,string,string,NuGet.Configuration.IMachineWideSettings,bool) <0x00418>
at NuGet.Configuration.Settings.LoadDefaultSettings (string,string,NuGet.Configuration.IMachineWideSettings,bool,bool) <0x0031e>
at NuGet.Configuration.Settings.LoadDefaultSettings (string,string,NuGet.Configuration.IMachineWideSettings) <0x00026>

Native stacktrace:

0   mono-sgen                           0x000000010e7c976a mono_handle_native_sigsegv + 282
1   libsystem_platform.dylib            0x00007fff8e929f1a _sigtramp + 26
2   mono-sgen                           0x000000010eab167f tmp_dir + 5471
3   libsystem_c.dylib                   0x00007fff86e909b3 abort + 129
4   mono-sgen                           0x000000010e96f7f3 monoeg_log_default_handler + 211
5   mono-sgen                           0x000000010e96f702 monoeg_g_logv + 114
6   mono-sgen                           0x000000010e96fb04 monoeg_assertion_message + 356
7   mono-sgen                           0x000000010e951740 own_if_owned + 0
8   mono-sgen                           0x000000010e8b8430 ves_icall_System_Threading_WaitHandle_WaitOne_internal + 96
9   ???                                 0x0000000113feccb4 0x0 + 4630432948
10  mscorlib.dll.dylib                  0x0000000110ac347e System_Threading_WaitHandle_WaitOne_System_TimeSpan + 30
11  ???                                 0x00000001264dffda 0x0 + 4937613274

The origin of the exception:

// Global: ensure mutex is honored across TS sessions 
using (var mutex = new Mutex(false, $"Global\\{EncryptionUtility.GenerateUniqueToken(fileName)}"))
{
    var owner = false;
    try
    {
        // operations on NuGet.config should be very short lived
        owner = mutex.WaitOne(TimeSpan.FromMinutes(1));
        // decision here is to proceed even if we were not able to get mutex ownership
        // and let the potential IO errors bubble up. Reasoning is that failure to get
        // ownership probably means faulty hardware and in this case it's better to report
        // back than hang
        ioOperation();
    }

(see https://github.com/NuGet/NuGet.Client/blob/58bd2dffe9cee8bf62b601f1610df4e9bbb91106/src/NuGet.Core/NuGet.Configuration/Settings/Settings.cs#L1134)

An observation: on CoreCLR+(Linux/MacOS), NuGet uses _globalMutex instead of named mutex because cross-plat CoreCLR doesn't support named locks. However, on Mono+(Linux/MacOS), NuGet tries to use a named mutex.

Linux version: Ubuntu 14.04
MacOS version: 10.10.5
Mono version: 4.2.3.4
NuGet.Client: 3.4.3

@rrelyea rrelyea added this to the 3.5 RC milestone May 31, 2016

@migueldeicaza

This comment has been minimized.

Show comment
Hide comment
@migueldeicaza

migueldeicaza Jun 23, 2016

Named mutexes in Mono are process-local, they are not global like they are on Windows, so on the Mono case, it should use the same setup.

In the past, many years ago, mono supported global mutexes across a processes in the user namespace, but that support was very brittle and we removed the code some 4-5 years ago.

Named mutexes in Mono are process-local, they are not global like they are on Windows, so on the Mono case, it should use the same setup.

In the past, many years ago, mono supported global mutexes across a processes in the user namespace, but that support was very brittle and we removed the code some 4-5 years ago.

@rrelyea rrelyea modified the milestones: 3.5 RTM, 3.6 Beta Jun 23, 2016

@rohit21agrawal

This comment has been minimized.

Show comment
Hide comment
@rohit21agrawal

rohit21agrawal Jun 29, 2016

Contributor

@AndreyAkinshin can you provide steps for triggering this exception?

Contributor

rohit21agrawal commented Jun 29, 2016

@AndreyAkinshin can you provide steps for triggering this exception?

@AndreyAkinshin

This comment has been minimized.

Show comment
Hide comment
@AndreyAkinshin

AndreyAkinshin Jun 29, 2016

@migueldeicaza, @rohit21agrawal, it is a bug in Mono, here is the bug report: https://bugzilla.xamarin.com/show_bug.cgi?id=41914
I think, you can fix the issue in NuGet using a global mutex (like in the CoreCLR case) instead of the named mutex.

@migueldeicaza, @rohit21agrawal, it is a bug in Mono, here is the bug report: https://bugzilla.xamarin.com/show_bug.cgi?id=41914
I think, you can fix the issue in NuGet using a global mutex (like in the CoreCLR case) instead of the named mutex.

@AndreyAkinshin

This comment has been minimized.

Show comment
Hide comment
@AndreyAkinshin

AndreyAkinshin Jun 29, 2016

Take the example from the bugreport and replace the mutex code by a LoadDefaultSettings invocation.

Take the example from the bugreport and replace the mutex code by a LoadDefaultSettings invocation.

@rohit21agrawal

This comment has been minimized.

Show comment
Hide comment
@rohit21agrawal

rohit21agrawal Jun 29, 2016

Contributor

@AndreyAkinshin
or we could detect at runtime if we are running on mono, and revert to using global mutex :

NuGet/NuGet.Client@218a1c1

Contributor

rohit21agrawal commented Jun 29, 2016

@AndreyAkinshin
or we could detect at runtime if we are running on mono, and revert to using global mutex :

NuGet/NuGet.Client@218a1c1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment