Repository navigation
Open
Description
I am getting segfaults from time to time. It seems to happen when python objects are wrapped and sent to the lua runtime.
Lupa version 1.4
Lua: tested version 5.1.5, 5.2.3, and luajit 2.0.4
Backtraces of the crash:
Lua:
#0 0x00007f639189c261 in lua_type () from /usr/lib64/liblua5.2.so.0
#1 0x00007f6391ae1b21 in __pyx_f_4lupa_5_lupa_lua_object_repr ()
from /home/micke/Documents/dev/telldus/tellstick-server/build/env/lib/python2.7/site-packages/lupa/_lupa.so
#2 0x00007f6391adf4ac in __pyx_pf_4lupa_5_lupa_10_LuaObject_14__str__ ()
from /home/micke/Documents/dev/telldus/tellstick-server/build/env/lib/python2.7/site-packages/lupa/_lupa.so
#3 0x00007f6391ade33d in __pyx_pw_4lupa_5_lupa_10_LuaObject_15__str__ ()
from /home/micke/Documents/dev/telldus/tellstick-server/build/env/lib/python2.7/site-packages/lupa/_lupa.so
#4 0x00007f63994c974a in _PyObject_Str () from /usr/lib64/libpython2.7.so.1.0
#5 0x00007f63994dad98 in PyString_Format () from /usr/lib64/libpython2.7.so.1.0
#6 0x00007f639952735f in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#7 0x00007f63995265cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#8 0x00007f63995265cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#9 0x00007f63995265cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#10 0x00007f63995265cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#11 0x00007f63995265cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#12 0x00007f63995265cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#13 0x00007f63995265cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#14 0x00007f6399529ad0 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0
#15 0x00007f63994b30cd in ?? () from /usr/lib64/libpython2.7.so.1.0
#16 0x00007f639948d333 in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#17 0x00007f639952365e in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#18 0x00007f6399529ad0 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0
#19 0x00007f63994b30cd in ?? () from /usr/lib64/libpython2.7.so.1.0
#20 0x00007f639948d333 in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#21 0x00007f639952365e in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#22 0x00007f6399529ad0 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0
#23 0x00007f63995264ae in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#24 0x00007f6399529ad0 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0
#25 0x00007f63994b30cd in ?? () from /usr/lib64/libpython2.7.so.1.0
#26 0x00007f639948d333 in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#27 0x00007f639952365e in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#28 0x00007f63995265cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#29 0x00007f63995265cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#30 0x00007f6399529ad0 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0
#31 0x00007f63994b2fec in ?? () from /usr/lib64/libpython2.7.so.1.0
#32 0x00007f639948d333 in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#33 0x00007f639949c275 in ?? () from /usr/lib64/libpython2.7.so.1.0
#34 0x00007f639948d333 in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#35 0x00007f639951fd77 in PyEval_CallObjectWithKeywords () from /usr/lib64/libpython2.7.so.1.0
#36 0x00007f6399558ab2 in ?? () from /usr/lib64/libpython2.7.so.1.0
#37 0x00007f639922c444 in start_thread () from /lib64/libpthread.so.0
#38 0x00007f6398f735ed in clone () from /lib64/libc.so.6
Luajit:
#0 0x00007f555d8a3c78 in lua_rawgeti () from /usr/lib64/libluajit-5.1.so.2
#1 0x00007f555db13b3e in __pyx_f_4lupa_5_lupa_10_LuaObject_push_lua_object ()
from /home/micke/Documents/dev/telldus/tellstick-server/build/env/lib/python2.7/site-packages/lupa/_lupa.so
#2 0x00007f555db15736 in __pyx_pf_4lupa_5_lupa_10_LuaObject_14__str__ ()
from /home/micke/Documents/dev/telldus/tellstick-server/build/env/lib/python2.7/site-packages/lupa/_lupa.so
#3 0x00007f555db152f7 in __pyx_pw_4lupa_5_lupa_10_LuaObject_15__str__ ()
from /home/micke/Documents/dev/telldus/tellstick-server/build/env/lib/python2.7/site-packages/lupa/_lupa.so
#4 0x00007f556550074a in _PyObject_Str () from /usr/lib64/libpython2.7.so.1.0
#5 0x00007f5565511d98 in PyString_Format () from /usr/lib64/libpython2.7.so.1.0
#6 0x00007f556555e35f in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#7 0x00007f556555d5cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#8 0x00007f556555d5cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#9 0x00007f556555d5cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#10 0x00007f556555d5cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#11 0x00007f556555d5cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#12 0x00007f556555d5cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#13 0x00007f556555d5cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#14 0x00007f5565560ad0 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0
#15 0x00007f55654ea0cd in ?? () from /usr/lib64/libpython2.7.so.1.0
#16 0x00007f55654c4333 in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#17 0x00007f556555a65e in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#18 0x00007f5565560ad0 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0
#19 0x00007f55654ea0cd in ?? () from /usr/lib64/libpython2.7.so.1.0
#20 0x00007f55654c4333 in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#21 0x00007f556555a65e in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#22 0x00007f5565560ad0 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0
#23 0x00007f556555d4ae in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#24 0x00007f5565560ad0 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0
#25 0x00007f55654ea0cd in ?? () from /usr/lib64/libpython2.7.so.1.0
#26 0x00007f55654c4333 in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#27 0x00007f556555a65e in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#28 0x00007f556555d5cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#29 0x00007f556555d5cb in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#30 0x00007f5565560ad0 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0
#31 0x00007f55654e9fec in ?? () from /usr/lib64/libpython2.7.so.1.0
#32 0x00007f55654c4333 in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#33 0x00007f55654d3275 in ?? () from /usr/lib64/libpython2.7.so.1.0
#34 0x00007f55654c4333 in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#35 0x00007f5565556d77 in PyEval_CallObjectWithKeywords () from /usr/lib64/libpython2.7.so.1.0
#36 0x00007f556558fab2 in ?? () from /usr/lib64/libpython2.7.so.1.0
#37 0x00007f5565263444 in start_thread () from /lib64/libpthread.so.0
#38 0x00007f5564faa5ed in clone () from /lib64/libc.so.6
Metadata
Metadata
Assignees
Labels
No labels
Activity
kmike commentedon May 10, 2017
I know it can be hard, but could you try creating a small-ish reproducible example?
mickeprag commentedon May 10, 2017
I have really tried boiling this down to a simple example to reproduce this issue. I am not sure I have succeded but in the mean time I have been able to reproduce a similar segfault. Not sure if this is the same issue.
This code segfaults roughly every ~500 iterations on my computer.
mickeprag commentedon May 17, 2017
I think I have some more information. I think the cause is two different threads try to access the lua runtime. The above example does this intentionally but in my software this is a side effect. Let me try to explain.
I have a lua runtime running in its own isolated thread. The lua thread tries to call some python code and I send this over to the python main thread to avoid concurrency issues. The python code gets a reference to the lua runtime (but never access it directly) in a wrapped object.
When python garbage-collects this object this is done in the main thread. The reference to the lua runtime is cleared (by the python interpreter, not my code) and it's here I get a segfault.
I have not managed to create an isolated example of this but it is fairly reproducible in my project. Here is an example of the wrapper object:
The segfault happens even without the destructor. I added the destructor with an implicit "freeing" of
cbto verify the backtrace that the segfault happens there.mickeprag commentedon May 17, 2017
Backtrace of the above observations:
mickeprag commentedon May 22, 2017
Finally, a small-ish reproducible example! No threads or anything special... ;)
https://gist.github.com/mickeprag/75a0fbf04cfd06c3fe48b759da22f5ef
xeor commentedon Aug 20, 2018
Did you do any more work on this? I'm new to lua, but have done my share of python.. can i help?
mickeprag commentedon Aug 20, 2018
I can only answer from my side. I have tried to see where the crash happen but I could not understand fully why.
If @kmike done anyting more, I do not know.
If you want to help. Start by see if you can reproduce the crash on your computer using my test-script.
scoder commentedon Aug 20, 2018
I can reproduce the crash, but the stack trace changes on each run. That suggests that there might be some kind of Lua stack corruption that only shows at a later point. Meaning, the crash is almost certainly not where the problem is.
xeor commentedon Aug 20, 2018
Able to reproduce using
Python 3.7.0andlupa 1.7..Going to test a couple of versions now
scoder commentedon Aug 20, 2018
xeor commentedon Aug 20, 2018
Tried a couple of random versions..
all crashes randomly between 15 and 400..
xeor commentedon Aug 20, 2018
Running the test and just watching it fail, dumps a lot of different errors on the console. Mostly segfaults, but also python malloc (
python: malloc.c:3760: _int_malloc: Assertion(unsigned long) (size) >= (unsigned long) (nb)' failed.`), errors and other python errors..This might be a stupid question, but if I move
thread = fn.coroutine()(https://gist.github.com/mickeprag/75a0fbf04cfd06c3fe48b759da22f5ef#file-crashtest-py-L39) outside the loop. It never fails.. Will it still work?scoder commentedon Aug 20, 2018
Maybe you could try to strip down the test case? It's very complex and uses lots of features: Lua couroutines, the
@unpacks_lua_tabledecorator, runtime options … Any feature that can be avoided will make it easier to find the place where things go wrong.xeor commentedon Aug 20, 2018
I'm very new to lua, so I'm not sure where to begin... I'll continue playing with it a little tho..
xeor commentedon Aug 20, 2018
Another strange find is that if I set anything under
selfto thecallbackobject passed into thePendingRequest, it crashes..Example..
is the original..
does not crash...
But
do crash..
mickeprag commentedon Aug 21, 2018
I have simplified the test case. Actually, removing the runtime options makes the script crash sooner on my machine.
I cannot reproduce the crash without using coroutines. Som my guess is that there is somewhere there the issue is.
Two observations:
PendingRequestinRequest.get()it does not crash.PendingRequest.__init__) is does not crash. Same observation as @xeor.Maybe this has something to do when the
PendingRequestobject is cleaned up by the Python garbage collector and it tries to release the reference to the lua-function? Just my speculations...xeor commentedon Aug 21, 2018
I tried to turn off gc.
import gc; gc.disable(), made no difference..noahcgreen commentedon Sep 9, 2020
Has there been any work done on this? I'm running into the same issue with coroutines unpredictably segfaulting.
mickeprag commentedon Sep 9, 2020
From my side, no, unfortunately not.
scoder commentedon Sep 10, 2020
There is a reproducing script in https://gist.github.com/mickeprag/75a0fbf04cfd06c3fe48b759da22f5ef
It's probably still not minimal and requires more investigation to find the point where things go wrong in the code.
Help with that is welcome.
noahcgreen commentedon Sep 15, 2020
Here's a slightly more minimal reproducing script:
Almost every time I run this I get an error similar to this:
So I do think it's likely there is some error with garbage collection/deallocation. I'm still not so comfortable debugging Cython but I'll try to look at this more over the weekend.