Bug 754 - IronPython stack overflow crashes Mono
Summary: IronPython stack overflow crashes Mono
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-09-12 08:19 UTC by Doug Blank
Modified: 2013-09-08 19:12 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 Doug Blank 2011-09-12 08:19:30 UTC
If you have a stack overflow in IronPython, then it crashes all of Mono, rather than raising an Exception.

Example:

$ mono ipy.exe
IronPython 3.0 (3.0.0.0) on .NET 2.0.50727.1433
Type "help", "copyright", "credits" or "license" for more information.
>>> def recur():
...     recur()
... 
>>> recur()
Stacktrace:


Native stacktrace:

	mono() [0x489171]
	mono() [0x4d154f]
	/lib/x86_64-linux-gnu/libpthread.so.0(+0xfc60) [0x7f2303075c60]
	mono() [0x4d1498]
	/lib/x86_64-linux-gnu/libpthread.so.0(+0xfc60) [0x7f2303075c60]
	[0x416921de]

Debug info from gdb:

Could not attach to process.  If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

Aborted

Appears to be a problem running in all versions of Mono including up to 2.10.x. Should raise a Python exception, and continue in IronPython.
Comment 1 Zoltan Varga 2011-09-14 09:17:28 UTC
Stack overflows are difficult to recover from, so the runtime usually prints a stack trace and terminates. I get:

Stack overflow: IP: 0x407844c3, fault addr: (nil)
Stacktrace:
  at IronPython.Runtime.Operations.PythonOps.GetVariable (IronPython.Runtime.CodeContext,
string,bool) <0x0006b>
  <...>
  at IronPython.Runtime.Operations.PythonOps.GetLocal (IronPython.Runtime.CodeContext,str
ing) <0x00013>
  at (wrapper dynamic-method) object.recur$2 (System.Runtime.CompilerServices.Closure,Iro
nPython.Runtime.PythonFunction) <0x000a1>
  at IronPython.Runtime.PythonFunction/FunctionCaller.Call0 (System.Runtime.CompilerServi
ces.CallSite,IronPython.Runtime.CodeContext,object) <0x000a2>
  at (wrapper dynamic-method) object.recur$2 (System.Runtime.CompilerServices.Closure,Iro
nPython.Runtime.PythonFunction) <0x000b9>
<etc>

What platform is this ? What is the output of mono --version ?
Comment 2 Doug Blank 2011-09-14 09:21:20 UTC
The output here is Linux, but I will test on all OS (I believe the behavior is the same).

As I mentioned, I have tried on many versions of Mono up to 2.10. Here is the output of one system that fails:

$ mono -V
Mono JIT compiler version 2.6.7 (Debian 2.6.7-5ubuntu3)
Copyright (C) 2002-2010 Novell, Inc and Contributors. www.mono-project.com
	TLS:           __thread
	GC:            Included Boehm (with typed GC and Parallel Mark)
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
Comment 3 Doug Blank 2011-09-14 09:26:45 UTC
Additional information:

One should be able to try/except the stack overflow in IronPython. Thus, the stack overflow in IronPython should not be a Mono stack overflow... there should be a level that Mono can catch the stack overflow in IronPython and deal with it accordingly. 

It looks like there is a conflation between the the IronPython exception raised, and a true CLR exception.

The code does not crash IronPython when running under .NET... it just raises the IronPython exception.
Comment 4 Doug Blank 2011-09-14 11:23:32 UTC
The sample IronPython code:

def recur():
    recur()
recur()

crashes on all operating systems, with all tested versions of Mono (including 2.8 on Windows, and 2.10.4 on Mac).

As far as I know, there are no known workarounds.

Please let me know if you need additional information.
Comment 5 Rodrigo Kumpera 2013-09-08 19:12:59 UTC
Mono now ship with proper stack overflow handling on all targets.