Skip to content
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

Segmentation fault from xcffib when quitting #626

Closed
kynikos opened this issue Mar 1, 2015 · 15 comments
Closed

Segmentation fault from xcffib when quitting #626

kynikos opened this issue Mar 1, 2015 · 15 comments

Comments

@kynikos
Copy link
Contributor

kynikos commented Mar 1, 2015

Tested with qtile 3eadbbf (latest commit while I'm writing) on Python3 with python-xcffib 0.2.0 in Arch Linux.
When exiting qtile, a segfault happens systematically if the screen has a Bar, regardless of the added widgets:

Segmentation fault (core dumped)

Sometimes, more or less randomly, better tracebacks are output:

Exception ignored in: <bound method Drawer.__del__ of <libqtile.drawer.Drawer object at 0x7ff5757b0358>>
Traceback (most recent call last):
  File "/mnt/archive/Development/qtile/bin/libqtile/drawer.py", line 233, in __del__
  File "/usr/lib/python3.4/site-packages/xcffib/xproto.py", line 2052, in FreeGC
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 355, in send_request
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 516, in wrapper
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 506, in invalid
xcffib.ConnectionException: xcb connection errors because of socket, pipe and other stream errors.
Exception ignored in: <bound method Drawer.__del__ of <libqtile.drawer.Drawer object at 0x7ff576165940>>
Traceback (most recent call last):
  File "/mnt/archive/Development/qtile/bin/libqtile/drawer.py", line 233, in __del__
  File "/usr/lib/python3.4/site-packages/xcffib/xproto.py", line 2052, in FreeGC
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 355, in send_request
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 516, in wrapper
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 506, in invalid
xcffib.ConnectionException: xcb connection errors because of socket, pipe and other stream errors.
Exception ignored in: <bound method Drawer.__del__ of <libqtile.drawer.Drawer object at 0x7ff576165f60>>
Traceback (most recent call last):
  File "/mnt/archive/Development/qtile/bin/libqtile/drawer.py", line 233, in __del__
  File "/usr/lib/python3.4/site-packages/xcffib/xproto.py", line 2052, in FreeGC
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 355, in send_request
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 516, in wrapper
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 506, in invalid
xcffib.ConnectionException: xcb connection errors because of socket, pipe and other stream errors.
Segmentation fault (core dumped)
Exception ignored in: <bound method Drawer.__del__ of <libqtile.drawer.Drawer object at 0x7f17fd2f9128>>
Traceback (most recent call last):
  File "/mnt/archive/Development/qtile/bin/libqtile/drawer.py", line 235, in __del__
  File "/usr/lib/python3.4/site-packages/xcffib/xproto.py", line 2052, in FreeGC
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 355, in send_request
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 516, in wrapper
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 506, in invalid
xcffib.ConnectionException: xcb connection errors because of socket, pipe and other stream errors.
Segmentation fault (core dumped)
Exception ignored in: <bound method Drawer.__del__ of <libqtile.drawer.Drawer object at 0x7fb5057aeac8>>
Traceback (most recent call last):
  File "/mnt/archive/Development/qtile/bin/libqtile/drawer.py", line 235, in __del__
  File "/usr/lib/python3.4/site-packages/xcffib/xproto.py", line 2052, in FreeGC
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 355, in send_request
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 516, in wrapper
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 506, in invalid
xcffib.ConnectionException: xcb connection errors because of socket, pipe and other stream errors.
Exception ignored in: <bound method Drawer.__del__ of <libqtile.drawer.Drawer object at 0x7fb5057ace80>>
Traceback (most recent call last):
  File "/mnt/archive/Development/qtile/bin/libqtile/drawer.py", line 235, in __del__
  File "/usr/lib/python3.4/site-packages/xcffib/xproto.py", line 2052, in FreeGC
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 355, in send_request
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 516, in wrapper
  File "/usr/lib/python3.4/site-packages/xcffib/__init__.py", line 506, in invalid
xcffib.ConnectionException: xcb connection errors because of socket, pipe and other stream errors.
Segmentation fault (core dumped)

No segfaults happen if the screen doesn't have a Bar or if it only has a Gap.

@tych0
Copy link
Member

tych0 commented Mar 1, 2015

Any chance you can run the whole thing in GDB so that it gives us a stack trace?

@kynikos
Copy link
Contributor Author

kynikos commented Mar 2, 2015

Yep

#0  0x00007ffff7d76600 in PyLong_Type () from /usr/lib/libpython3.4m.so.1.0
#1  0x00007ffff1c4ade7 in ?? () from /usr/lib/libxcb.so.1
#2  0x00007ffff1c4ae69 in ?? () from /usr/lib/libxcb.so.1
#3  0x00007ffff1c4b3ec in xcb_send_request () from /usr/lib/libxcb.so.1
#4  0x00007ffff1e644c0 in ?? () from /usr/lib/python3.4/site-packages/_xcffib.cpython-34m.so
#5  0x00007ffff7a5bef9 in call_function (oparg=<optimized out>, pp_stack=0x7fffffffd590) at Python/ceval.c:4237
#6  PyEval_EvalFrameEx (f=0x555555b6a748, throwflag=<optimized out>) at Python/ceval.c:2838
#7  0x00007ffff7a5d45f in PyEval_EvalCodeEx (_co=0x0, globals=0x4, locals=0x555555b6a8c0, args=0x7ffff42753d0, argcount=1441017272, kws=0x14, kws@entry=0x0, kwcount=-228779872, defs=0x0, 
    defcount=0, kwdefs=0x0, closure=0x0) at Python/ceval.c:3588
#8  0x00007ffff79ce6f9 in function_call (func=0x7ffff20a1620, arg=0x7ffff42753b8, kw=0x0) at Objects/funcobject.c:632
#9  0x00007ffff79a5e71 in PyObject_Call (func=func@entry=0x7ffff20a1620, arg=arg@entry=0x7ffff42753b8, kw=kw@entry=0x0) at Objects/abstract.c:2040
#10 0x00007ffff7a56907 in ext_do_call (nk=<optimized out>, na=0, flags=<optimized out>, pp_stack=0x7fffffffd858, func=0x7ffff20a1620) at Python/ceval.c:4561
#11 PyEval_EvalFrameEx (f=0x7ffff2570248, throwflag=<optimized out>) at Python/ceval.c:2878
#12 0x00007ffff7a5d45f in PyEval_EvalCodeEx (_co=0x0, _co@entry=0x7ffff25cdf60, globals=0x0, locals=0x7ffff25703c0, args=0x555555cf2678, argcount=1441017272, argcount@entry=4, kws=0x14, 
    kwcount=-228794528, defs=0x0, defcount=0, kwdefs=0x0, closure=0x7ffff207e550) at Python/ceval.c:3588
#13 0x00007ffff7a5b52f in fast_function (nk=0, na=4, n=<optimized out>, pp_stack=0x7fffffffda50, func=<optimized out>) at Python/ceval.c:4344
#14 call_function (oparg=<optimized out>, pp_stack=0x7fffffffda50) at Python/ceval.c:4262
#15 PyEval_EvalFrameEx (f=0x555555cf24a8, throwflag=<optimized out>) at Python/ceval.c:2838
#16 0x00007ffff7a5d45f in PyEval_EvalCodeEx (_co=0x0, _co@entry=0x7ffff25cd0c0, globals=0x7ffff2646cb0, locals=0x555555cf2620, args=0x7ffff262a6c0, argcount=1441017272, argcount@entry=3, 
    kws=0x14, kwcount=-228798272, defs=0x7ffff2098210, defcount=3, kwdefs=0x0, closure=0x0) at Python/ceval.c:3588
#17 0x00007ffff7a5b52f in fast_function (nk=1, na=3, n=<optimized out>, pp_stack=0x7fffffffdc50, func=<optimized out>) at Python/ceval.c:4344
#18 call_function (oparg=<optimized out>, pp_stack=0x7fffffffdc50) at Python/ceval.c:4262
#19 PyEval_EvalFrameEx (f=0x7fffeb348228, throwflag=<optimized out>) at Python/ceval.c:2838
#20 0x00007ffff7a5d45f in PyEval_EvalCodeEx (_co=0x0, _co@entry=0x7ffff182c540, globals=0x2, locals=0x7fffeb3483a0, args=0x7fffeb34a6d8, argcount=1441017272, argcount@entry=2, kws=0x14, 
    kwcount=-243088064, defs=0x7ffff17ec5a0, defcount=1, kwdefs=0x0, closure=0x0) at Python/ceval.c:3588
#21 0x00007ffff7a5b52f in fast_function (nk=0, na=2, n=<optimized out>, pp_stack=0x7fffffffde50, func=<optimized out>) at Python/ceval.c:4344
#22 call_function (oparg=<optimized out>, pp_stack=0x7fffffffde50) at Python/ceval.c:4262
#23 PyEval_EvalFrameEx (f=0x7fffeb34a558, throwflag=<optimized out>) at Python/ceval.c:2838
#24 0x00007ffff7a5d45f in PyEval_EvalCodeEx (_co=0x0, globals=0x1, locals=0x7fffeb34a6d0, args=0x7ffff5c44958, argcount=1441017272, kws=0x14, kws@entry=0x0, kwcount=-243963888, defs=0x0, 
    defcount=0, kwdefs=0x0, closure=0x0) at Python/ceval.c:3588
#25 0x00007ffff79ce6f9 in function_call (func=0x7ffff175e510, arg=0x7ffff5c44940, kw=0x0) at Objects/funcobject.c:632
#26 0x00007ffff79a5e71 in PyObject_Call (func=func@entry=0x7ffff175e510, arg=arg@entry=0x7ffff5c44940, kw=kw@entry=0x0) at Objects/abstract.c:2040
#27 0x00007ffff79bb20d in method_call (func=0x7ffff175e510, arg=0x7ffff5c44940, kw=0x0) at Objects/classobject.c:347
#28 0x00007ffff79a5e71 in PyObject_Call (func=func@entry=0x7ffff5c4a388, arg=arg@entry=0x7ffff7f88048, kw=0x0) at Objects/abstract.c:2040
#29 0x00007ffff7a54357 in PyEval_CallObjectWithKeywords (func=func@entry=0x7ffff5c4a388, arg=0x7ffff7f88048, arg@entry=0x0, kw=kw@entry=0x0) at Python/ceval.c:4114
#30 0x00007ffff79fdc2d in slot_tp_finalize (self=<optimized out>) at Objects/typeobject.c:6233
#31 0x00007ffff7a93d69 in finalize_garbage (collectable=0x7fffffffe1a0) at Modules/gcmodule.c:808
#32 collect (generation=generation@entry=2, n_collected=n_collected@entry=0x0, n_uncollectable=n_uncollectable@entry=0x0, nofail=nofail@entry=1) at Modules/gcmodule.c:1021
#33 0x00007ffff7a94b01 in _PyGC_CollectNoFail () at Modules/gcmodule.c:1638
#34 0x00007ffff7a6eaa9 in PyImport_Cleanup () at Python/import.c:483
#35 0x00007ffff7a7b2b6 in Py_Finalize () at Python/pythonrun.c:616
#36 0x00007ffff7a92a14 in Py_Main (argc=0, argv=0x0) at Modules/main.c:771
#37 0x0000555555554c06 in main ()

@tych0
Copy link
Member

tych0 commented Mar 2, 2015

Huh, interesting. It looks like that should be protected in xcffib, but apparently it's not :). I'll take a closer look at some point; does this keep it from segfaulting at least? http://paste.ubuntu.com/10502050/

@kynikos
Copy link
Contributor Author

kynikos commented Mar 3, 2015

Nope, that patch doesn't avoid the segfault :(

@tych0
Copy link
Member

tych0 commented Mar 3, 2015

Huh, ok. Thanks, I'll keep thinking about it :)

@tych0
Copy link
Member

tych0 commented Mar 3, 2015

Can you post your config that crashes, by chance?

@kynikos
Copy link
Contributor Author

kynikos commented Mar 4, 2015

This is a minimal config that produces the segfault when quitting with Super+Ctrl+q immediately after starting:

from libqtile.config import Key, Screen, Group, Drag, Click
from libqtile.command import lazy
from libqtile import layout, bar, widget, hook

keys = [Key(["mod4", "control"], "q", lazy.shutdown())]
groups = [Group("a")]
layouts = [layout.Max()]
screens = [Screen(
    bottom=bar.Bar([], 32),
)]

Tested with qtile 989f0f8, Python 3.4.3, xcffib 0.2.0, Xorg 1.17.1, Intel graphics (driver 2.99.917) in Arch Linux x86_64 up-to-date as of 2015-03-04 (Linux 3.18.6).

Commenting the bottom=bar.Bar([], 32), line avoids the segfault.

@tych0
Copy link
Member

tych0 commented Mar 10, 2015

Hmm. So I tried reproducing this myself and I couldn't get it to fail. What I suspect is happening is destructor ordering strangeness; something like python is deleting globals from out from under xcffib before the del methods in qtile are called.

However, that's just a guess. The stack trace you posted is a little confusing to me, because as far as I know xcffib should never call back into python, but it seems to by (viz. the PyLong_Type call at the top of the stack). Any chance you can install xcb's debug symbols and run it again?

@kynikos
Copy link
Contributor Author

kynikos commented Mar 14, 2015

Um... sorry, this bug only happens in a very particular scenario, i.e. when launching qtile from an already started Xorg session. What I do for testing is having a .xinitrc script similar this:

# ~/.xinitrc
exec xterm

Once X is started with startx or xinit -- :1, I launch qtile manually in the terminal from the repo folder with ./bin/qtile -c test.py, so I can read the output in the terminal emulator more easily than in the virtual console. In this case, when quitting, the segfault is always raised.
I confirm that when qtile is launched directly from .xinitrc, the segfault doesn't happen for me either.
Maybe this bug is the symptom of something that should be fixed in xcffib anyway, I don't know, if you think it's useful I can try to install xcb's debug symbols to help you further, or you can try to reproduce the scenario I've described above.

luxrck added a commit to luxrck/qtile that referenced this issue Apr 5, 2015
luxrck added a commit to luxrck/qtile that referenced this issue Apr 5, 2015
@tych0
Copy link
Member

tych0 commented Apr 13, 2015

Hi,

@luxrck's patch seems to indicate it's a problem with gobject, does tych0@d33b200 fix it?

@flacjacket
Copy link
Member

Hmm, is this still a problem? If so, any chance #702 fixes it?

@kynikos
Copy link
Contributor Author

kynikos commented Jul 18, 2015

TBH I still have problems when testing as explained in my post above: if you want I can post outputs and backtraces, maybe it's the symptom of some other problem that might affect something else, however you may instead decide that testing qtile that way is not supported, and I'd be fine with that ^^

@flacjacket
Copy link
Member

Ah, I see, this is a different segfault then you mentioned here, I think I fixed that one, but I haven't seen this one. I can try to reproduce it later tonight.

@kynikos
Copy link
Contributor Author

kynikos commented Jul 19, 2015

The generated exceptions/segfaults seem to vary quite a bit for me depending on the checked-out commit. For example, with the latest commit, after starting X as explained above I get an exception when trying to launch qtile with ./bin/qtile -c test.py, and the only way to test it is install the commit system-wide, and then run qtile -c test.py, which however still segfaults when quitting.

@github-actions
Copy link

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants