[Mono-dev] StackOverflow on System.Delegate.Equals

Miguel de Icaza miguel at novell.com
Wed Mar 30 16:04:45 EDT 2011

> I've found an issue in my ASP.NET application when it's running under heavy
> load. It throws an exception like that: http://pastebin.com/DRAYVM0F and
> then the whole application is down, i've to restart apache/mod-mono-server.
> It's running under mono 2.10.1, apache2 and mod-mono. On IIS/MS.NET i've not
> found any problems, even on heavier load. Maybe someone has any
> thoughts/ideas what might causing problem like this? Thanks in advance. 

What could be happening is that the event is being accessed in a thread
unsafe way, and the internals of the delegate are in a state of flux by
the time the invocation for equals takes place.

So one thread is doing:

	foo += bar

While another one is doing an equality test, the state is half-built.
The way you could instrument this is to rewrite that routine to not be
recursive, but instead to be iterative, and have a maximum count,
something like:

	MulticastDelegate track_this = this;
	MulticastDelegate track_other = d;

	for (int i = 0; i < 10000; i++){
		object this_prev = track_this.prev;
		object other_prev = d.prev;

		if (this_prev != other_prev)
			return false;
	if (i == 10000)
		Console.WriteLine ("The corrupted instance is {0}", this.GetType ());

	return true;

That will tell you the type that is getting corrupted.   It will help
determine if this is a bug in Mono, or your code.


More information about the Mono-devel-list mailing list