You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Recursive logging crashes Interpreter in Python 3 #80453
I am not sure this is related to logging and looks similar to bpo-35542 except stack (depends on OS) is exhausted without setrecursionlimit(). What does below return?
defrec():
rec()
rec()
SaimRaza commented on Mar 13, 2019
SaimRazamannequin
MannequinAuthor
More actions
Stack exhaustion doesn't seem to be due to be the root cause. A simple recursive function doesn't crash the interpreter in Python 3.6.
>>> defrec(): rec()
>>> rec()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in rec
File "<stdin>", line 1, in rec
File "<stdin>", line 1, in rec
[Previous line repeated 995 more times]
RecursionError: maximum recursion depth exceeded
I think there is two ways to solve the issue, either handle RecursionError explicitly in the logging module so we don't clear it inadvertently as there is no way to recover from it anyway or check if the exception has been cleared at https://github.com/python/cpython/blob/master/Python/ceval.c#L531 and set it again.
Handling it explictly in the logging module would not help for code doing this elsewhere:
Activity
SaimRaza commentedon Mar 12, 2019
Following code logs an error and calls itself leading to stack overflow and eventually core dump in Python 3.6.
[1] 101641 abort (core dumped) python3
FTR, this doesn't crash Python 2.7.
Attaching the error (condensed) in Python 3.6:
ERROR:root:foo
...
--- Logging error ---
RuntimeError: maximum recursion depth exceeded
But no core dump in Python 2.7.
FTR, the error above with Python 3.6 will come into play if the log level is set to logging.ERROR. Similarly for other log levels.
tirkarthi commentedon Mar 12, 2019
I am not sure this is related to logging and looks similar to bpo-35542 except stack (depends on OS) is exhausted without setrecursionlimit(). What does below return?
SaimRaza commentedon Mar 13, 2019
Stack exhaustion doesn't seem to be due to be the root cause. A simple recursive function doesn't crash the interpreter in Python 3.6.
remilapeyre commentedon Mar 13, 2019
I'm not sure bpo-35542. I think this happens because while logging the recursion limit is hit which calls https://github.com/python/cpython/blob/master/Python/ceval.c#L535-L539.
The RecursionError is then handled by https://github.com/python/cpython/blob/master/Lib/logging/__init__.py#L1000 and cleared.
On subsequent calls the exception is not set anymore because
tstate->overflowedequals 1 so we exit early before setting the exception again at https://github.com/python/cpython/blob/master/Python/ceval.c#L531.This goes on until the condition on https://github.com/python/cpython/blob/master/Python/ceval.c#L531 pass which abort the interpreter.
I think there is two ways to solve the issue, either handle RecursionError explicitly in the logging module so we don't clear it inadvertently as there is no way to recover from it anyway or check if the exception has been cleared at https://github.com/python/cpython/blob/master/Python/ceval.c#L531 and set it again.
Handling it explictly in the logging module would not help for code doing this elsewhere:
I can submit a patch if you want.
remilapeyre commentedon Mar 13, 2019
The following patch fixes the issue and raise RecursionError as expecting without core dump:
tirkarthi commentedon Mar 13, 2019
Yes, sorry I got misleaded. I have added logging module author, @vinay.sajip to the issue.
brettcannon commentedon Mar 13, 2019
Limiting the version scope to 3.6 until someone reproduces on 3.7 and/or 3.8.
remilapeyre commentedon Mar 13, 2019
Hi Brett, I confirm the test case breaks both Python3.7 and 3.8. I opened a PR to fix the problem.
vsajip commentedon Mar 15, 2019
New changeset 65f64b1 by Vinay Sajip (Rémi Lapeyre) in branch 'master':
bpo-36272: Logging now propagates RecursionError (GH-12312)
65f64b1
vsajip commentedon Mar 18, 2019
New changeset 6a7a9f1 by Vinay Sajip (Miss Islington (bot)) in branch '3.7':
bpo-36272: Logging now propagates RecursionError (GH-12312) (GH-12391)
6a7a9f1