altdesktop / i3ipc-glib

A C interface library to i3wm
GNU General Public License v3.0
104 stars 18 forks source link

Crash on i3 restart #11

Open denesb opened 8 years ago

denesb commented 8 years ago

While investigating this issue I consistently met crashes inside i3ipc-glib when restarting i3. Since I wasn't entirely confident that the bug was not in my code I created a minimal program to reproduce the issue (see reproduce.txt) and on my box this crashes approximately 1 out of 5 times upon restarting i3. This is the stack trace on my box:

#0  0x00007ffff4f2b5a0 in xcb_setup_vendor_end () from /usr/lib/libxcb.so.1
#1  0x00007ffff4f2b5f9 in xcb_setup_pixmap_formats_iterator () from /usr/lib/libxcb.so.1
#2  0x00007ffff4f2b639 in xcb_setup_roots_iterator () from /usr/lib/libxcb.so.1
#3  0x00007ffff7bd2984 in i3ipc_connection_get_socket_path (err=0x7fffffffdcd8, self=0x6025c0) at i3ipc-connection.c:375
#4  i3ipc_connection_initable_init (initable=<optimized out>, cancellable=<optimized out>, err=0x602598) at i3ipc-connection.c:668
#5  0x00007ffff7bd2e9e in i3ipc_connected_constructed (gobject=0x6025c0) at i3ipc-connection.c:151
#6  0x00007ffff798d897 in ?? () from /usr/lib/libgobject-2.0.so.0
#7  0x00007ffff798f1b5 in g_object_new_valist () from /usr/lib/libgobject-2.0.so.0
#8  0x00007ffff60c081e in g_initable_new_valist () from /usr/lib/libgio-2.0.so.0
#9  0x00007ffff60c08e6 in g_initable_new () from /usr/lib/libgio-2.0.so.0
#10 0x00007ffff7bd3198 in i3ipc_connection_new (socket_path=0x0, err=0x7fffffffe150) at i3ipc-connection.c:346
#11 0x000000000040092b in construct (err=0x7fffffffe180) at reproduce.c:10
#12 0x00000000004009ae in on_shutdown (connection=0x602340, data=0x0) at reproduce.c:33
#13 0x00007ffff79881d4 in ?? () from /usr/lib/libgobject-2.0.so.0
#14 0x00007ffff79a29d6 in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#15 0x00007ffff79a30bf in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#16 0x00007ffff7bd4b64 in ipc_on_data (channel=<optimized out>, condition=G_IO_IN, conn=0x602340) at i3ipc-connection.c:535
#17 0x00007ffff76b1dba in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#18 0x00007ffff76b2160 in ?? () from /usr/lib/libglib-2.0.so.0
#19 0x00007ffff76b2482 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#20 0x00007ffff71554e7 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
#21 0x0000000000400a31 in main () at reproduce.c:47

My plugin always crashes at i3ipc-connection.c:539 also, although the stack below is different. Anyone else had this issue?

denesb commented 8 years ago

I forgot to mention: I use the latest version of i3ipc-glib from master.

acrisci commented 8 years ago

Crashing is something we should never do so I will look into how to fix that.

i3#2318 will add a proper shutdown event to the ipc protocol which will help with this a lot. I would like to add this to the 2.0 release. That should also enable the possibility of a flag on the connection that will make it automatically reconnect on restarts.

In general, since restart is such a hard command to handle from the ipc, I recommend people not use it at all, and instead use reload which should have all the same functionality but with less bugs.

acrisci commented 8 years ago

Also, I plan to deprecate the "ipc-shutdown" event in favor of the new event (which I will call simply "shutdown") that will be totally supported by the protocol. The new auto reconnect flag I'm planning with that event should handle your use case well for recent versions of i3 (when the event is implemented) by reconnecting to the socket internally so you won't have a need to recreate the object.

denesb commented 8 years ago

OK, thanks for the heads up. I'll hold off fixing my issue until 2.0 is released.