New submission from Adrien <delgan...@gmail.com>:

This is an issue that I first saw repoted by @remi.lapeyre on issue36272: 
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:


def rec():
    try:
        rec()
    except Exception:
        rec()
rec()


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 issue36272 solely patches "StreamHandler": 
https://github.com/python/cpython/blob/65f64b1903ae85b97a30f514bbc1b7ce940c3af2/Lib/logging/__init__.py#L1082-L1102
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.

----------
messages: 346232
nosy: Delgan
priority: normal
severity: normal
status: open
title: RecursionError not caught explicitly may crash with "Aborted (core 
dumped)"
type: crash

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37365>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to