-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
repeated Py_Initialize/PyRun_SimpleString/Py_Finalize segfaults #71923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
dbus-python has a regression test for https://bugs.freedesktop.org/show_bug.cgi?id=23831 which repeatedly initializes the interpreter, imports dbus and finalizes the interpreter. This test passes in Python up to 3.5, but is failing under Python 3.6 nightly builds on Travis-CI, and in Python 3.6.0a3 (package version 3.6.0~a3-1) on Debian. I've been able to reproduce the crash without anything specific to dbus with this C code: #include <stdio.h>
#include <Python.h>
int main(void)
{
int i;
for (i = 0; i < 100; ++i) {
Py_Initialize();
if (PyRun_SimpleString("\n") != 0) {
puts("not ok 1 - there was an exception");
return 1;
}
Py_Finalize();
}
return 0;
} It appears the crash is reliably in the 10th repeat: Program received signal SIGSEGV, Segmentation fault. |
This might be a duplicate of https://bugs.python.org/issue24853 but there wasn't enough detail on that bug for me to be sure. |
Thanks for the good test, Simon. Bisection points to b841972ed0bd for bpo-27038 as the culprit here. (It was pushed between 3.6.0a2 and a3.) Brett, Jelle, can you please take a look at this? I'm going to keep it as a Release Blocker for now. |
The revision that Ned found only changed posixmodule.c by adding PyModule_AddObject(m, "DirEntry", (PyObject *)&DirEntryType); at the end of the module initializer. Only thing I can think of is it needs to go into the Line 13214 in 11b4800
Line 13259 in 11b4800
|
It looks to me from the traceback Simon given that DirEntryType's dealloc function is called. From the code, shouldn't we Py_INCREF DirEntryType before PyModule_AddObject? |
Try Simon's snippet I think I am right. With the current code, the result is: 1..1 With Py_INCREF: 1..1 I upload the working patch. |
Thanks for the patch. FWIW, that does seem to solve the crash. Brett, look good to you? If so, I can push the fix. |
Patch LGTM. |
New changeset a95d98086621 by Ned Deily in branch 'default': |
I've applied the patch for 3.6.0a4 so the immediate issue is fixed. I wonder if it would be worthwhile adapting Simon's test case to add to the embedding test cases in Lib/test/test_capi.py. I'm going to leave the issue open for a while in case someone is interested in doing that. |
We don't have to change Lib/test/test_capi.py. It has already got a repeated init and fini test[1]. All we need to do is increase the loop number[2]. I have tried with 15, the test case fails reliably. And with the previous patch applied, it won't fail. [1] https://hg.python.org/cpython/file/tip/Lib/test/test_capi.py#l386 |
New changeset 4f69626fd923 by Ned Deily in branch 'default': |
Excellent! Thanks for digging into that. Increasing the iterations seems to work fine within the (understandable) limitations of the existing embedded tests, e.g. only work from a source tree build (not an installed build nor from a separate build directory) etc. Case closed. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: