Bug 26550 - Calling event with to many listeners causes stack overflow
Summary: Calling event with to many listeners causes stack overflow
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: 3.8.0
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Ludovic Henry
URL:
: 26387 ()
Depends on:
Blocks:
 
Reported: 2015-01-29 12:36 UTC by Lukas Grundmann
Modified: 2015-05-05 14:46 UTC (History)
3 users (show)

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


Attachments
unready fix attempts for this bug and bug 26387 (5.89 KB, patch)
2015-02-07 09:23 UTC, Lukas Grundmann
Details


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 Lukas Grundmann 2015-01-29 12:36:30 UTC
Calling an event with to much listeners causes a stack overflow.

You can trigger the bug by adding several thousand listeners to an event and call it in a thread with small stack size.

Following code snippet should reproduce the bug:

class MainClass
	{
		static event EventHandler<int> ev;

		public static void Main (string[] args)
		{

			for (int i = 0; i < 2000; i++) {
				ev += (sender, x) => Console.WriteLine(x);
			}

			Thread t = new Thread (() => ev (null, 11), 128 * 1024);
			t.Start ();
		}
	}
Comment 1 João Matos 2015-01-30 11:06:30 UTC
Joaos-iMac:scripts joao$ mono test.exe
Stack overflow in unmanaged: IP: 0x250a2c, fault addr: 0xb011dfdc
Stack overflow in unmanaged: IP: 0x938ea94e, fault addr: 0xb011cffc
Stack overflow in unmanaged: IP: 0x949de4d7, fault addr: 0xb011bfec
Stack overflow in unmanaged: IP: 0x1d4860, fault addr: 0xb011bf5c
Stack overflow in unmanaged: IP: 0x1bd5ec, fault addr: 0xb011bf7c
Stack overflow in unmanaged: IP: 0x12480c, fault addr: 0xb011bf7c
Stack overflow in unmanaged: IP: 0x12480c, fault addr: 0xb011bf8c
Stack overflow in unmanaged: IP: 0x19c56c, fault addr: 0xb011bffc

Unhandled Exception:
: The requested operation caused a stack overflow.
[ERROR] FATAL UNHANDLED EXCEPTION: : The requested operation caused a stack overflow.
Comment 2 Lukas Grundmann 2015-02-07 09:23:10 UTC
Created attachment 9695 [details]
unready fix attempts for this bug and bug 26387

Patch contains my fix attempts for this bug and bug 26387.

Unfortunately it lets test-anon-(58-61) in the compiler tests fail.

So far I don't know what I'm doing wrong. Maybe someone else?
Comment 3 João Matos 2015-02-07 09:36:39 UTC
Hi Lukas,

I started look into this one yesterday but didn't have much time to make any meaningful progress besides looking at the relevant areas of the codebase. Next week I plan to tackle it, your patches will be most welcome.
Comment 4 Ludovic Henry 2015-05-04 11:19:03 UTC
Hi Lukas,

It should be fixed by https://github.com/mono/mono/pull/1757 I tried with 100000 delegates and it didn't crash on my machine. I am actively working on getting this PR merged into master.

Ludovic
Comment 5 Lukas Grundmann 2015-05-04 11:50:48 UTC
Hi Ludovic,

that are excellent news!

Thank you very much for this. Your changes also should have fixed bug 26387.
Comment 6 Ludovic Henry 2015-05-05 05:59:50 UTC
*** Bug 26387 has been marked as a duplicate of this bug. ***