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
RecursionError not caught explicitly may crash with "Aborted (core dumped)" #81546
bpo-18075: Infinite recursion tests triggering a segfault
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2019-06-21.18:35:45.627>created_at=<Date2019-06-21.16:08:01.315>labels= ['type-crash']
title='RecursionError not caught explicitly may crash with "Aborted (core dumped)"'updated_at=<Date2019-06-22.08:12:39.116>user='https://github.com/Delgan'
It will kill the CPython interpreter (@remi.lapeyre provided explanation in the issue I linked).
Of course, this is a contrived example. Still, I guess CPython should avoid to crash in any situation. This is a tricky edge case: by doing `except Exception:` one could expect to correctly handle all kind of errors without being aware that in some situation the "RecursionError" need to be managed too.
Particularly, the fix in bpo-36272 solely patches "StreamHandler":
Finally, it should also be noted that the "except RecursionError" workaround implies that loggers are not longer able to catch recursive erros in "write()" or "format()" without re-raising the RecursionError and (probably) halting the program.
It may happen for example that a faulty implementation of a custom Handler or LogRecord attribute cause a RecursionError. Thanks to the "raiseExceptions = false" logging option, this would usually be caught and a message printed on stderr without killing the app.
Thank you for the report. The issue of the interpreter not being able to gracefully handle a stack overflow error is an old one: see, for example bpo-18075 or bpo-35542. So far, no one has proposed a solution and, as can be seen in bpo-18075, workarounds someimes produce unexpected side-effects that can be more problematic than the stack overflow segfault. I'm going to close this as a duplicate of bpo-18075. If anyone has further suggestions for solutions, please continue the discussion there.
Sorry to insist, but are you sure this is a duplicate of bpo-18075 / bpo-35542?
According to the discussion in bpo-36272, it seems this is not related to stack exhaustion nor to bpo-18075.
Also, @remi.lapeyre suggested that a fix could be possible by modifying ceval.c. (re-raise RecursionError if it has been cleared).
bpo-18075 and bpo-35542 are both of status "closed", I would expect this issue to be duplicate to an "open" issue because there is a clear reproducible "bug" which crashes the interpreter.
There is also the problems still remaining in logging Handlers that I linked.
I think this is an issue with how recursion error are handled in ceval.c, this is related to "tstate->overflowed" and "tstate->recursion_depth > recursion_limit + 50".
If I understand correctly, this is implemented like this to allow gracefully catch and handle RecursionError from the calling function.
For example, why not re-raise the exception if the first one could not be handled correctly?
Activity
Delgan commentedon Jun 21, 2019
This is an issue that I first saw repoted by @remi.lapeyre on bpo-36272: https://bugs.python.org/issue36272#msg337843
It also be reported some years ago: https://stackoverflow.com/a/54171640/2291710
I searched but I did not find any existing issue, so I open a new one, I hope this is not a duplicate.
It's easily reproducible:
It will kill the CPython interpreter (@remi.lapeyre provided explanation in the issue I linked).
Of course, this is a contrived example. Still, I guess CPython should avoid to crash in any situation. This is a tricky edge case: by doing `except Exception:` one could expect to correctly handle all kind of errors without being aware that in some situation the "RecursionError" need to be managed too.
Particularly, the fix in bpo-36272 solely patches "StreamHandler":
cpython/Lib/logging/__init__.py
Lines 1082 to 1102 in 65f64b1
There is many other handlers that are still affected, every time you see "except Exception" in "emit()": https://github.com/python/cpython/blob/65f64b1903ae85b97a30f514bbc1b7ce940c3af2/Lib/logging/handlers.py
Finally, it should also be noted that the "except RecursionError" workaround implies that loggers are not longer able to catch recursive erros in "write()" or "format()" without re-raising the RecursionError and (probably) halting the program.
It may happen for example that a faulty implementation of a custom Handler or LogRecord attribute cause a RecursionError. Thanks to the "raiseExceptions = false" logging option, this would usually be caught and a message printed on stderr without killing the app.
ned-deily commentedon Jun 21, 2019
Thank you for the report. The issue of the interpreter not being able to gracefully handle a stack overflow error is an old one: see, for example bpo-18075 or bpo-35542. So far, no one has proposed a solution and, as can be seen in bpo-18075, workarounds someimes produce unexpected side-effects that can be more problematic than the stack overflow segfault. I'm going to close this as a duplicate of bpo-18075. If anyone has further suggestions for solutions, please continue the discussion there.
Delgan commentedon Jun 22, 2019
Thanks to your answer, @ned.deily.
Sorry to insist, but are you sure this is a duplicate of bpo-18075 / bpo-35542?
According to the discussion in bpo-36272, it seems this is not related to stack exhaustion nor to bpo-18075.
Also, @remi.lapeyre suggested that a fix could be possible by modifying ceval.c. (re-raise RecursionError if it has been cleared).
bpo-18075 and bpo-35542 are both of status "closed", I would expect this issue to be duplicate to an "open" issue because there is a clear reproducible "bug" which crashes the interpreter.
There is also the problems still remaining in logging Handlers that I linked.
I think this is an issue with how recursion error are handled in ceval.c, this is related to "tstate->overflowed" and "tstate->recursion_depth > recursion_limit + 50".
If I understand correctly, this is implemented like this to allow gracefully catch and handle RecursionError from the calling function.
For example, why not re-raise the exception if the first one could not be handled correctly?