Title: module can set an exception in tp_clear
Type: crash Stage:
Components: Interpreter Core Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: petr.viktorin, serhiy.storchaka, vstinner
Priority: normal Keywords:

Created on 2018-05-31 12:21 by serhiy.storchaka, last changed 2018-09-11 22:06 by petr.viktorin.

Messages (2)
msg318289 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-05-31 12:21
The tp_clear handler of the module object calls a custom clear function if the PyModuleDef.m_clear field is set. This function can set an exception which will be leaked to the garbage collector. An exception in tp_clear is not expected and caused a crash in the garbage collector. In the master branch it will cause just writing a traceback to stderr (see issue33622), but in any case it would be better to handle the failure locally in the module's tp_clear.
msg325075 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2018-09-11 22:06
I'm not sure what tp_clear should do in this situation.
Other than propagating the exception to the GC, the most reasonable behavior seems to be to write the exception to stderr and ignore it -- but I think having the GC do that would be more robust.

IOW, I think raising an exception from tp_clear is reasonable, and if that caused (causes?) a crash, it's a bug.
Date User Action Args
2018-09-11 22:06:33petr.viktorinsetmessages: + msg325075
2018-05-31 14:18:40vstinnersetnosy: + petr.viktorin
2018-05-31 14:18:31vstinnersetnosy: + vstinner
2018-05-31 12:21:45serhiy.storchakacreate