classification
Title: faulthandler: fatal error with "SystemError: null argument to internal routine"
Type: crash Stage: patch review
Components: Interpreter Core Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pitrou, vstinner, yselivanov, zbysz
Priority: normal Keywords: patch

Created on 2012-05-19 08:53 by zbysz, last changed 2014-02-01 00:03 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
issue14854_faulthandler_tests.diff zbysz, 2012-05-19 18:47 two tests for faulthandler initialization review
issue14854_faulthandler_tests.diff zbysz, 2012-05-20 22:31 two tests for faulthandler initialization review
Messages (10)
msg161097 - (view) Author: Zbyszek Jędrzejewski-Szmek (zbysz) * Date: 2012-05-19 08:53
Simply running './python -X faulthandler' in the source directory gives me this:

% ./python -X faulthandler
Fatal Python error: Py_Initialize: can't initialize faulthandler
SystemError: null argument to internal routine
[1]    25118 abort (core dumped)  ./python -X faulthandler

% gdb ./python core
Core was generated by `./python -X faulthandler'.
Program terminated with signal 6, Aborted.
#0  0x00007f52d7ff9475 in *__GI_raise (sig=<optimized out>)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
64	../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  0x00007f52d7ff9475 in *__GI_raise (sig=<optimized out>)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1  0x00007f52d7ffc6f0 in *__GI_abort () at abort.c:92
#2  0x00000000004bc984 in Py_FatalError (msg=0x5b3750 "Py_Initialize: can't initialize faulthandler")
    at Python/pythonrun.c:2283
#3  0x00000000004b85ed in Py_InitializeEx (install_sigs=1) at Python/pythonrun.c:361
#4  0x00000000004b86ea in Py_Initialize () at Python/pythonrun.c:398
#5  0x00000000004d55a6 in Py_Main (argc=3, argv=0x1b8f010) at Modules/main.c:624
#6  0x000000000041b120 in main (argc=3, argv=0x7fffc1ebb558) at ./Modules/python.c:65
(gdb) 
#0  0x00007f52d7ff9475 in *__GI_raise (sig=<optimized out>)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1  0x00007f52d7ffc6f0 in *__GI_abort () at abort.c:92
#2  0x00000000004bc984 in Py_FatalError (msg=0x5b3750 "Py_Initialize: can't initialize faulthandler")
    at Python/pythonrun.c:2283
#3  0x00000000004b85ed in Py_InitializeEx (install_sigs=1) at Python/pythonrun.c:361
#4  0x00000000004b86ea in Py_Initialize () at Python/pythonrun.c:398
#5  0x00000000004d55a6 in Py_Main (argc=3, argv=0x1b8f010) at Modules/main.c:624
#6  0x000000000041b120 in main (argc=3, argv=0x7fffc1ebb558) at ./Modules/python.c:65
msg161114 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-05-19 13:43
Here is a patch:


$ hg di
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -356,15 +356,15 @@ Py_InitializeEx(int install_sigs)
 
     _PyImportHooks_Init();
 
-    /* initialize the faulthandler module */
-    if (_PyFaulthandler_Init())
-        Py_FatalError("Py_Initialize: can't initialize faulthandler");
-
     /* Initialize _warnings. */
     _PyWarnings_Init();
 
     import_init(interp, sysmod);
 
+    /* initialize the faulthandler module */
+    if (_PyFaulthandler_Init())
+        Py_FatalError("Py_Initialize: can't initialize faulthandler");
+
     _PyTime_Init();
 
     if (initfsencoding(interp) < 0)
msg161140 - (view) Author: Zbyszek Jędrzejewski-Szmek (zbysz) * Date: 2012-05-19 17:29
I can confirm that it works with the patch. Thanks!
msg161142 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-05-19 17:59
The patch looks good to me.
msg161143 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-05-19 17:59
Hum, a test may be added to ensure that we will not have the regression anymore.
msg161149 - (view) Author: Zbyszek Jędrzejewski-Szmek (zbysz) * Date: 2012-05-19 18:47
% PYTHONFAULTHANDLER=1 ./python -E -c 'import faulthandler; faulthandler._sigsegv()'
[3]    14516 segmentation fault (core dumped)

Unless I'm missing something, the env. var. is not working as documented.

Patch with two tests is attached: the first does 'python -X faulthandler ...' and passes after Antoine's patch, the second does 'PYTHONFAULTHANDLER=YesPlease python ...' and does not pass.
msg161152 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-05-19 19:18
> PYTHONFAULTHANDLER=1 ./python -E ...

Documentation of the -E option "Ignore all PYTHON* environment
variables, e.g. PYTHONPATH and PYTHONHOME, that might be set."
http://docs.python.org/dev/using/cmdline.html#cmdoption-E

So the option works as expected.
msg161237 - (view) Author: Zbyszek Jędrzejewski-Szmek (zbysz) * Date: 2012-05-20 22:31
A new version of the tests: one for 'python -X faulthandler', one for 'PYTHONFAULTHANDLER=1 python'. This one sets the environment properly for the second test, but is slightly more invasive.

Both tests fail without Antoine's patch, and both succeed when it is applied.
msg209835 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-01-31 22:09
bump?
msg209848 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-02-01 00:03
Oh, in fact I already fixed this issue long time ago in Python 3.3 and 3.4.
---
changeset:   78341:2f1494d243ad
user:        Victor Stinner <victor.stinner@gmail.com>
date:        Tue Jul 31 02:55:49 2012 +0200
files:       Lib/test/test_faulthandler.py Python/pythonrun.c
description:
Fix initialization of the faulthandler module

faulthandler requires the importlib if "-X faulthandler" option is present on
the command line, so initialize faulthandler after importlib.

Add also an unit test.
---

I'm closing the issue. Thanks for the report.
History
Date User Action Args
2014-02-01 00:03:31vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg209848

versions: + Python 3.3
2014-01-31 22:09:59yselivanovsetnosy: + yselivanov

messages: + msg209835
versions: + Python 3.4, - Python 3.3
2012-05-20 22:31:41zbyszsetfiles: + issue14854_faulthandler_tests.diff

messages: + msg161237
2012-05-20 22:02:37pitrousetstage: patch review
type: crash
components: + Interpreter Core
versions: + Python 3.3
2012-05-19 19:18:19vstinnersetmessages: + msg161152
2012-05-19 18:47:30zbyszsetfiles: + issue14854_faulthandler_tests.diff
keywords: + patch
messages: + msg161149
2012-05-19 17:59:37vstinnersetmessages: + msg161143
2012-05-19 17:59:06vstinnersetmessages: + msg161142
2012-05-19 17:29:12zbyszsetmessages: + msg161140
2012-05-19 13:43:10pitrousetnosy: + pitrou
messages: + msg161114
2012-05-19 09:06:49zbyszsettitle: faulthandler: segfault with "SystemError: null argument to internal routine" -> faulthandler: fatal error with "SystemError: null argument to internal routine"
2012-05-19 08:53:12zbyszcreate