Issue 3605: Py_FatalError causes infinite loop (original) (raw)

Created on 2008-08-19 20:42 by rupole, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 17080 merged vstinner,2019-11-07 10:32
Messages (11)
msg71478 - (view) Author: Roger Upole (rupole) Date: 2008-08-19 20:42
Py_FatalError calls PyErr_Occurred() which requires a current thread state. This mean that if the original error was a thread state error Py_FatalError is triggered again, ad infinitum.
msg71485 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-08-19 21:08
Do you have a simple code sample to showcase that?
msg71487 - (view) Author: Roger Upole (rupole) Date: 2008-08-19 21:28
Py_BEGIN_ALLOW_THREADS PyErr_SetString(PyExc_SystemError, "bork bork bork"); Py_END_ALLOW_THREADS
msg71488 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-08-19 21:30
> Roger Upole <rupole@hotmail.com> added the comment: > > Py_BEGIN_ALLOW_THREADS > PyErr_SetString(PyExc_SystemError, "bork bork bork"); > Py_END_ALLOW_THREADS Well, if you start using all kinds of internal APIs without holding the GIL, you should expect much worse than just a Py_FatalError ;-) Of course, it would still be better if the infinite loop could be avoided.
msg71489 - (view) Author: Roger Upole (rupole) Date: 2008-08-19 21:43
Well, you asked for a simple case. In practice, I'm dealing with much more complicated code that contains callbacks which may need to acquire or release the theadlock. This problem makes it very difficult to debug such code. Also, the PyErr_Occurred is not present in 2.5.2, probably for this very same reason.
msg105612 - (view) Author: Jeffrey Yasskin (jyasskin) * (Python committer) Date: 2010-05-12 23:36
I have a fix at http://codereview.appspot.com/1184043, which makes PyErr_Occurred() return NULL when there is no thread. I'll commit it tomorrow unless there are comments.
msg105650 - (view) Author: Jeffrey Yasskin (jyasskin) * (Python committer) Date: 2010-05-13 18:31
Fixed in r81142.
msg105781 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-05-15 01:43
I fixed the new test for Windows: r81183 (py3k). The new test failed on Windows because of the different newline characters: Traceback (most recent call last): File "...\test_capi.py", line 49, in test_no_FatalError_infinite_loop b'Fatal Python error:' AssertionError: b'Fatal Python error: PyThreadState_Get: no current thread\r\n' != b'Fatal Python error: PyThreadState_Get: no current thread\n'
msg120302 - (view) Author: Roger Upole (rupole) Date: 2010-11-03 02:32
I know this has been closed, but I disagree with the fix. Py_FatalError is designed to give a clean exit with a readable error message when the state of the interpreter is known to be compromised. Calling *any* python functions or accessing *any* python internals is only likely to lead to more issues that obscure the original problems. IMO the PyErr_Occurred needs to be removed entirely.
msg141289 - (view) Author: Neil Aspinall (mocmocamoc) * Date: 2011-07-28 10:58
Would it be possible for this issue's fix (PyErr_Occurred() returning null when the thread state is null) to be applied to the 2.7 branch?
msg356185 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-11-07 11:42
New changeset d12d0e7c0fe2b49c40ac4d66365147c619d6c475 by Victor Stinner in branch 'master': bpo-38733: PyErr_Occurred() caller must hold the GIL (GH-17080) https://github.com/python/cpython/commit/d12d0e7c0fe2b49c40ac4d66365147c619d6c475
History
Date User Action Args
2022-04-11 14:56:37 admin set github: 47855
2019-11-07 11:42:22 vstinner set messages: +
2019-11-07 10:32:10 vstinner set pull_requests: + <pull%5Frequest16590>
2011-07-28 11:16:29 schmir set nosy: + schmir
2011-07-28 10:58:49 mocmocamoc set nosy: + mocmocamocmessages: +
2010-11-03 02:32:47 rupole set messages: +
2010-05-15 01:43:35 vstinner set nosy: + vstinnermessages: +
2010-05-13 18:31:36 jyasskin set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2010-05-12 23:36:22 jyasskin set nosy: + jyasskinmessages: + assignee: jyasskinkeywords: + needs reviewstage: test needed -> patch review
2009-10-22 10:40:40 lekma set nosy: + lekma
2009-05-16 22:17:00 ajaksu2 set priority: normalstage: test neededtype: behaviorversions: + Python 3.1, - Python 3.0
2008-08-19 22:02:03 ajaksu2 set nosy: + ajaksu2
2008-08-19 21:43:34 rupole set messages: +
2008-08-19 21:30:30 pitrou set messages: +
2008-08-19 21:28:33 rupole set messages: +
2008-08-19 21:08:04 pitrou set nosy: + pitroumessages: +
2008-08-19 20:42:18 rupole create