Repository: IronLanguages/ironpython3

Issue #1234: Application crashes if there is infinite recursion at Python code.
Created: 2021-05-24T17:54:19Z
Prerequisites
The issue tracker is used to report bugs and request new features, NOT to ask questions.
Questions should be posted to the users mailing list which can be accessed at
https://ironpython.groups.io/g/users.

 Are you running the latest version?
 Are you reporting to the correct repository?
 Did you perform a cursory search?

Description
Embedded IronPython causes crash of application if there is infinite recursion. It should raise RecursionError
(since Python 3.5) or RuntimeError (before Python 3.5) instead.
Steps to Reproduce
Following C# code can be used to reproduce it:
    var engine = IronPython.Hosting.Python.CreateEngine();
    var script = @"
def func():
    func()

try:
    func()
except Exception:
    print('Failed to call func')
";
    engine.Execute(script);

Expected behavior:
Printing "Failed to call func".
Actual behavior:
Application exited with Access violation Error.
Versions
3.4.0-alpha

Duplicate issue #1263: Recursive function call crashes IronPython 
Created: 2021-08-03T05:16:49Z
The following test case can work well on CPython and report a Recursive error. However it crashes IronPython.
test.py
def foo():
    foo()
foo()


Crash report

.......
at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet] (T0 arg0) [0x0003e] in <252827dbc7924637ba1c8c95b5f54810>:0
at IronPython.Compiler.PythonCallTargets.OriginalCallTarget0 (IronPython.Runtime.PythonFunction function) [0x00017] in <5cd2739cd27844619789a1aa1ffdb0b0>:0
at IronPython.Runtime.FunctionCaller.Call0 (System.Runtime.CompilerServices.CallSite site, IronPython.Runtime.CodeContext context, System.Object func) [0x00023] in <5cd2739cd27844619789a1aa1ffdb0b0>:0
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet] (System.Runtime.CompilerServices.CallSite site, T0 arg0, T1 arg1) [0x00035] in <5b415632df1f4365ae2242b1a257bb5b>:0
at Microsoft.Scripting.Interpreter.FuncCallInstruction`5[T0,T1,T2,T3,TRet].Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00000] in <252827dbc7924637ba1c8c95b5f54810>:0
at Microsoft.Scripting.Interpreter.Interpreter.Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00016] in <252827dbc7924637ba1c8c95b5f54810>:0
at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet] (T0 arg0, T1 arg1, T2 arg2) [0x0005c] in <252827dbc7924637ba1c8c95b5f54810>:0
at IronPython.Compiler.Ast.CallExpression+Invoke0Instruction.Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x0001f] in <5cd2739cd27844619789a1aa1ffdb0b0>:0
at Microsoft.Scripting.Interpreter.Interpreter.Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00016] in <252827dbc7924637ba1c8c95b5f54810>:0
at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet] (T0 arg0) [0x0003e] in <252827dbc7924637ba1c8c95b5f54810>:0
at IronPython.Compiler.RuntimeScriptCode.InvokeTarget (Microsoft.Scripting.Runtime.Scope scope) [0x0006a] in <5cd2739cd27844619789a1aa1ffdb0b0>:0
at IronPython.Compiler.RuntimeScriptCode.Run (Microsoft.Scripting.Runtime.Scope scope) [0x00000] in <5cd2739cd27844619789a1aa1ffdb0b0>:0
at IronPython.Hosting.PythonCommandLine.RunFileWorker (System.String fileName) [0x000e5] in <5cd2739cd27844619789a1aa1ffdb0b0>:0
at IronPython.Hosting.PythonCommandLine.RunFile (System.String fileName) [0x0000f] in <5cd2739cd27844619789a1aa1ffdb0b0>:0
at Microsoft.Scripting.Hosting.Shell.CommandLine.Run () [0x0003a] in <252827dbc7924637ba1c8c95b5f54810>:0
at IronPython.Hosting.PythonCommandLine.Run () [0x000d8] in <5cd2739cd27844619789a1aa1ffdb0b0>:0
at Microsoft.Scripting.Hosting.Shell.CommandLine.Run (Microsoft.Scripting.Hosting.ScriptEngine engine, Microsoft.Scripting.Hosting.Shell.IConsole console, Microsoft.Scripting.Hosting.Shell.ConsoleOptions options) [0x0003c] in <252827dbc7924637ba1c8c95b5f54810>:0
at Microsoft.Scripting.Hosting.Shell.ConsoleHost.RunCommandLine () [0x00053] in <252827dbc7924637ba1c8c95b5f54810>:0
at Microsoft.Scripting.Hosting.Shell.ConsoleHost.ExecuteInternal () [0x00051] in <252827dbc7924637ba1c8c95b5f54810>:0
at PythonConsoleHost.ExecuteInternal () [0x00025] in <9cafe2448f474c41b81ba0c1d71815eb>:0
at Microsoft.Scripting.Hosting.Shell.ConsoleHost.Execute () [0x00032] in <252827dbc7924637ba1c8c95b5f54810>:0
at Microsoft.Scripting.Hosting.Shell.ConsoleHost.Run (System.String[] args) [0x0015b] in <252827dbc7924637ba1c8c95b5f54810>:0
at PythonConsoleHost.Main (System.String[] args) [0x00020] in <9cafe2448f474c41b81ba0c1d71815eb>:0

System

IronPython 3.4.0a1 (3.4.0.0001)
[.NETFramework,Version=v4.6 on Mono 6.12.0.122 (64-bit)] on linux

Closing comment (2021-08-03T12:13:42Z): Duplicate of #1234. The difference in behavior is documented here: https://github.com/IronLanguages/ironpython3/blob/master/Documentation/differences-from-c-python.md#recursion