Issue 30817: Abort in PyErr_PrintEx() when no memory (original) (raw)
Created on 2017-06-30 14:19 by xdegaye, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Messages (9)
Author: Xavier de Gaye (xdegaye) *
Date: 2017-06-30 14:19
To reproduce the abort (the set_nomemory() function is being added to _testcapi in issue 30695):
$ ./python memerr.py python: Objects/call.c:89: _PyObject_FastCallDict: Assertion `!PyErr_Occurred()' failed. Aborted (core dumped)
The corresponding backtrace:
#0 0x00007ffff7131670 in raise () from /usr/lib/libc.so.6 #1 0x00007ffff7132d00 in abort () from /usr/lib/libc.so.6 #2 0x00007ffff712a45a in __assert_fail_base () from /usr/lib/libc.so.6 #3 0x00007ffff712a4d2 in __assert_fail () from /usr/lib/libc.so.6 #4 0x00000000004628ce in _PyObject_FastCallDict ( callable=<built-in method excepthook of module object at remote 0x7ffff70ab8d8>, args=args@entry=0x7fffffffe330, nargs=nargs@entry=3, kwargs=kwargs@entry=0x0) at Objects/call.c:89 #5 0x0000000000426004 in PyErr_PrintEx (set_sys_last_vars=set_sys_last_vars@entry=1) at Python/pythonrun.c:641 #6 0x00000000004263ac in PyErr_Print () at Python/pythonrun.c:510 #7 0x0000000000427586 in PyRun_SimpleFileExFlags (fp=fp@entry=0x987620, filename=, filename@entry=0x7ffff6febcd0 "memerr.py", closeit=closeit@entry=1, flags=flags@entry=0x7fffffffe4cc) at Python/pythonrun.c:403 #8 0x0000000000427673 in PyRun_AnyFileExFlags (fp=fp@entry=0x987620, filename=0x7ffff6febcd0 "memerr.py", closeit=closeit@entry=1, flags=flags@entry=0x7fffffffe4cc) at Python/pythonrun.c:82 #9 0x0000000000437217 in run_file (fp=fp@entry=0x987620, filename=0x91a190 L"memerr.py", p_cf=p_cf@entry=0x7fffffffe4cc) at Modules/main.c:341 #10 0x0000000000437bae in Py_Main (argc=argc@entry=2, argv=argv@entry=0x918020) at Modules/main.c:901 #11 0x000000000041d7fa in main (argc=2, argv=0x7fffffffe6c8) at ./Programs/python.c:102
Author: Xavier de Gaye (xdegaye) *
Date: 2017-06-30 14:21
With pyerr_printex.patch we get the following correct results (rc=120 is set by Py_Main() after Py_FinalizeEx() returns with an error):
$ ./python memerr.py 5 12 set_nomemory(0, 5) result = _PythonRunResult(rc=1, out=b'', err=b'MemoryError\n\nDuring handling of the above exception, another exception occurred:\n\nMemoryError')
set_nomemory(0, 6) result = _PythonRunResult(rc=1, out=b'', err=b'sys.excepthook is missing\nMemoryError\n\nDuring handling of the above exception, another exception occurred:\n\nMemoryError')
set_nomemory(0, 7) result = _PythonRunResult(rc=1, out=b'', err=b'sys.excepthook is missing\nMemoryError\n\nDuring handling of the above exception, another exception occurred:\n\nMemoryError')
set_nomemory(0, 8) result = _PythonRunResult(rc=1, out=b'', err=b'sys.excepthook is missing\nobject : MemoryError()\ntype : MemoryError\nrefcount: 1\naddress : 0x7f7ae1be3eb0\nlost sys.stderr')
set_nomemory(0, 9) result = _PythonRunResult(rc=1, out=b'', err=b'sys.excepthook is missing\nobject : \ntype : MemoryError\nrefcount: 1\naddress : 0x7f8aead15eb0\nlost sys.stderr')
set_nomemory(0, 10) result = _PythonRunResult(rc=1, out=b'', err=b'sys.excepthook is missing\nobject : \ntype : MemoryError\nrefcount: 1\naddress : 0x7f7b489d1eb0\nlost sys.stderr')
set_nomemory(0, 11) result = _PythonRunResult(rc=1, out=b'', err=b'sys.excepthook is missing\nobject : \ntype : MemoryError\nrefcount: 1\naddress : 0x7ff97365eeb0\nlost sys.stderr')
set_nomemory(0, 12) result = _PythonRunResult(rc=120, out=b'', err=b"sys.excepthook is missing\nobject : \ntype : MemoryError\nrefcount: 1\naddress : 0x7f559c9e0eb0\nlost sys.stderr\nException ignored in: <_io.TextIOWrapper name='' mode='w' encoding='UTF-8'>\nMemoryError")
Author: STINNER Victor (vstinner) *
Date: 2017-06-30 14:51
pyerr_printex.patch LGTM, please convert it to a GitHub PR.
Author: Serhiy Storchaka (serhiy.storchaka) *
Date: 2017-07-01 17:05
Is it good to ignore errors of setting sys attributes? Can we prevent these errors?
Author: Xavier de Gaye (xdegaye) *
Date: 2017-07-01 19:58
There are just 6 cases left where the return code of _PySys_SetObjectId() is ignored:
Python/pylifecycle.c|689 col 5| _PySys_SetObjectId(&PyId_stderr, pstderr); Python/pylifecycle.c|1211 col 9| _PySys_SetObjectId(&PyId_stderr, pstderr); Python/pylifecycle.c|1657 col 5| _PySys_SetObjectId(&PyId_stdin, std); Python/pylifecycle.c|1666 col 5| _PySys_SetObjectId(&PyId_stdout, std); ./Python/pythonrun.c|104 col 9| _PySys_SetObjectId(&PyId_ps1, v = PyUnicode_FromString(">>> ")); ./Python/pythonrun.c|109 col 9| _PySys_SetObjectId(&PyId_ps2, v = PyUnicode_FromString("... "));
Error should be handled there in the same way errors are handled within the functions where they are invoked (returning -1, NULL or aborting). This should be the purpose of another issue as it is acceptable I think that there is no test case for those changes.
I am leaving the day after tomorrow for few weeks, without internet access (sailing to the mid-atlantic), and will create then a new issue if no one else does that first.
Author: Serhiy Storchaka (serhiy.storchaka) *
Date: 2017-07-02 05:21
I tried to set last_type, last_value and last_traceback to None at startup, and this also fixes a crash. But this changes behavior (these attributes became set), and deleting them doesn't guaranties that following setting will be successful, especially with new compact dict implementation.
Author: Xavier de Gaye (xdegaye) *
Date: 2017-10-23 15:03
Removing 2.7 as the problem cannot be reproduced here. PyEval_CallObjectWithKeywords() does not assert on PyErr_Occurred().
Author: Xavier de Gaye (xdegaye) *
Date: 2017-10-23 16:08
New changeset 66caacf2f0d6213b049a3097556e28e30440b900 by xdegaye in branch 'master': bpo-30817: Fix PyErr_PrintEx() when no memory (#2526) https://github.com/python/cpython/commit/66caacf2f0d6213b049a3097556e28e30440b900
Author: Xavier de Gaye (xdegaye) *
Date: 2017-10-24 14:42
New changeset d5d79545b73110b2f4c2b66d150409514e2ca8e0 by xdegaye in branch '3.6': [3.6] bpo-30817: Fix PyErr_PrintEx() when no memory (GH-2526). (#4107) https://github.com/python/cpython/commit/d5d79545b73110b2f4c2b66d150409514e2ca8e0
History
Date
User
Action
Args
2022-04-11 14:58:48
admin
set
github: 75000
2017-10-24 14:44:13
xdegaye
set
status: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-10-24 14:42:38
xdegaye
set
messages: +
2017-10-24 14:10:46
xdegaye
set
pull_requests: + <pull%5Frequest4077>
2017-10-23 16:08:43
xdegaye
set
messages: +
2017-10-23 15:03:35
xdegaye
set
messages: +
versions: - Python 2.7
2017-10-23 13:26:26
xdegaye
set
stage: patch review
versions: - Python 3.5
2017-07-02 05:21:22
serhiy.storchaka
set
files: + set-last-exception.diff
messages: +
2017-07-01 19:58:34
xdegaye
set
messages: +
2017-07-01 17:05:47
serhiy.storchaka
set
nosy: + serhiy.storchaka
messages: +
2017-07-01 13:43:57
xdegaye
set
pull_requests: + <pull%5Frequest2591>
2017-06-30 14:51:16
vstinner
set
nosy: + vstinner
messages: +
2017-06-30 14:21:16
xdegaye
set
files: + pyerr_printex.patch
keywords: + patch
messages: +
2017-06-30 14:19:31
xdegaye
create