[issue36272] Recursive logging crashes Interpreter in Python 3

Rémi Lapeyre report at bugs.python.org
Wed Mar 13 07:20:00 EDT 2019


Rémi Lapeyre <remi.lapeyre at henki.fr> added the comment:

I'm not sure issue35542. 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->overflowed` equals 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:

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


I can submit a patch if you want.

----------
nosy: +remi.lapeyre
versions: +Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36272>
_______________________________________


More information about the Python-bugs-list mailing list