Bug 14058 - Assertion at debugger-agent.c:5101, condition `tls->context.valid' not met
Summary: Assertion at debugger-agent.c:5101, condition `tls->context.valid' not met
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: Debugger ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Zoltan Varga
URL:
Depends on:
Blocks:
 
Reported: 2013-08-17 18:05 UTC by Marek Safar
Modified: 2015-10-08 09:31 UTC (History)
3 users (show)

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

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 Marek Safar 2013-08-17 18:05:01 UTC
//
//  Test.cs
//
//  Author:
//       Mario Jungwirth <mj@netbits.at>
//
//  Copyright (c) 2013 netbits.at @ Mario Jungwirth
//
using System;
using System.Threading;
using System.Collections.Generic;

namespace TestThreadingLocking
{
	public class Lock
	{
		ReaderWriterLockSlim _Lock1 = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion); //.SupportsRecursion); //.NoRecursion); //.SupportsRecursion);
		object _Lock2 = new object();
		ushort _UseLock = 1;

		public Lock( ushort UseLock_)
		{
			_UseLock = UseLock_;
		}

		public void EnterReadLock()
		{
			switch( _UseLock )
			{
				case 1:
					_Lock1.EnterReadLock();
					break;
				case 2:
					Monitor.Enter( _Lock2 );
					break;
			}
		}

		public void ExitReadLock()
		{
			switch( _UseLock )
			{
				case 1:
					_Lock1.ExitReadLock();
					break;
				case 2:
					Monitor.Exit( _Lock2 );
					break;
			}
		}

		public void EnterWriteLock()
		{
			switch( _UseLock )
			{
				case 1:
					_Lock1.EnterWriteLock();
					break;
				case 2:
					Monitor.Enter( _Lock2 );
					break;
			}
		}

		public void ExitWriteLock()
		{
			switch( _UseLock )
			{
				case 1:
					_Lock1.ExitWriteLock();
					break;
				case 2:
					Monitor.Exit( _Lock2 );
					break;
			}
		}

	}

	public class Test
	{
		Lock _Lock;
		ulong _Counter = 0;

		public Test( ushort UseLock_ )
		{
			_Lock = new Lock( UseLock_ );
		}

		public void Start()
		{
			List<Thread> _threds = new List<Thread>();
			for( int i = 0; i < 20; i++ )
			{
				Thread t = new Thread( _ThreadRunHandler );
				_threds.Add( t );
				t.Start();
			}

			while( true )
			{
				ulong count;

				_Lock.EnterReadLock();
				count = _Counter;
				_Lock.ExitReadLock();

				Console.WriteLine( "count = {0}.", count);

				if( count > 500 )
					break;

				Thread.Sleep( 1000 );
			}
		}

		void _ThreadRunHandler()
		{
			while( true )
			{
				try
				{
					_Lock.EnterReadLock();
					if( _Counter > 500 )
						break;
				}
				finally
				{
					_Lock.ExitReadLock();
				}

				_Lock.EnterWriteLock();
				++_Counter;
				_Lock.ExitWriteLock();
			}
		}
	}
}
Comment 1 Marek Safar 2013-08-17 18:06:52 UTC
Set a breakpoint in ReaderWriterLockSlim::TryEnterReadLock (int millisecondsTimeout, ref bool success)

at line 133 in master mono and do step over when the breakpoint is hit few time. After 5-10 stop over

* Assertion at debugger-agent.c:5101, condition `tls->context.valid' not met

Stacktrace:


Native stacktrace:

	0   mono                                0x0015445b mono_handle_native_sigsegv + 379
	1   mono                                0x001dc1dd sigabrt_signal_handler + 141
	2   libsystem_c.dylib                   0x9170559b _sigtramp + 43
	3   ???                                 0xffffffff 0x0 + 4294967295
	4   libsystem_c.dylib                   0x916a0bdd abort + 167
	5   mono                                0x003b73f3 monoeg_g_logv + 291
	6   mono                                0x003b7486 monoeg_assertion_message + 54
	7   mono                                0x00189a87 ss_create + 583
	8   mono                                0x0019055f event_commands + 2959
	9   mono                                0x00197253 debugger_thread + 1331
	10  mono                                0x0039596a thread_start_routine + 234
	11  mono                                0x003b0528 inner_start_thread + 152
	12  libsystem_c.dylib                   0x916aded9 _pthread_start + 335
	13  libsystem_c.dylib                   0x916b16de thread_start + 34
Comment 2 Marek Safar 2013-08-19 04:24:29 UTC
Forget to include the program runner. It very simple

//
//  Program.cs
//
//  Author:
//       Mario Jungwirth <mj@netbits.at>
//
//  Copyright (c) 2013 netbits.at @ Mario Jungwirth
//
using System;
using System.Threading;

namespace TestThreadingLocking
{
	class MainClass
	{
		public static void Main( string[] args )
		{
			Test t = new Test(1);
			t.Start();
		}
	}
}
Comment 3 Zoltan Varga 2013-08-23 18:03:20 UTC
This is a regression caused by 5ddbe31ee5c42f5e379cb077e3473667791bc15a. We interrupt a thread while it is hitting a breakpoint, and invalidate its context, leading to this assert.
Comment 4 Zoltan Varga 2013-09-16 14:46:58 UTC
Reverted 5ddbe31ee5c42f5e379cb077e3473667791bc15a which caused this.
Comment 5 Ola Østtveit 2015-10-08 09:31:52 UTC
I have problems lately when debugging on Android and getting SIGABRT without any information, but today I got this message about condition 'tls->context.valid' not met.

Using Visual Studio 2012 with Xamarin 3.11.1443.0, Xamarin.Android 5.1.6.7 and debugging on a Samsung Galaxy Note4.