After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 350776 - Crash closing gedit with something on the clipboard
Crash closing gedit with something on the clipboard
Status: RESOLVED FIXED
Product: gedit
Classification: Applications
Component: general
2.15.x
Other All
: High critical
: 2.16.0
Assigned To: Gedit maintainers
Gedit maintainers
: 351094 351160 351243 352486 441678 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2006-08-10 16:57 UTC by Sean Wilson
Modified: 2007-07-26 23:36 UTC
See Also:
GNOME target: ---
GNOME version: 2.15/2.16


Attachments
Full backtrace of hello, copy and exit (6.49 KB, text/plain)
2006-08-18 17:41 UTC, Andrew
  Details
patch (2.24 KB, patch)
2006-08-26 15:00 UTC, Paolo Borelli
committed Details | Review

Description Sean Wilson 2006-08-10 16:57:26 UTC
What were you doing when the application crashed?
Closed gedit after viewing a text file


Distribution: Gentoo Base System version 1.6.14
Gnome Release: 2.15.91 2006-08-09 (JHBuild)
BugBuddy Version: 2.15.90

Memory status: size: 104738816 vsize: 0 resident: 104738816 share: 0 rss: 20811776 rss_rlim: 0
CPU usage: start_time: 1155228448 rtime: 0 utime: 664 stime: 0 cutime:638 cstime: 0 timeout: 26 it_real_value: 0 frequency: 0

Backtrace was generated from '/usr/bin/gedit'

Using host libthread_db library "/lib/tls/libthread_db.so.1".
`system-supplied DSO at 0xffffe000' has disappeared; keeping its symbols.
[Thread debugging using libthread_db enabled]
[New Thread 1865635504 (LWP 7631)]
0xffffe410 in __kernel_vsyscall ()

Thread 1 (Thread 1865635504 (LWP 7631))

  • #0 __kernel_vsyscall
  • #1 __waitpid_nocancel
    from /lib/tls/libpthread.so.0
  • #2 libgnomeui_segv_handle
    at gnome-ui-init.c line 867
  • #3 <signal handler called>
  • #4 __kernel_vsyscall
  • #5 raise
    from /lib/tls/libc.so.6
  • #6 abort
    from /lib/tls/libc.so.6
  • #7 IA__g_logv
    at gmessages.c line 497
  • #8 IA__g_log
    at gmessages.c line 517
  • #9 IA__g_return_if_fail_warning
    at gmessages.c line 532
  • #10 IA__gtk_container_foreach
    at gtkcontainer.c line 1283
  • #11 IA__gtk_container_get_children
    at gtkcontainer.c line 1373
  • #12 update_node
    at gtkuimanager.c line 2154
  • #13 update_node
    at gtkuimanager.c line 2567
  • #14 update_node
    at gtkuimanager.c line 2567
  • #15 do_updates
    at gtkuimanager.c line 2609
  • #16 do_updates_idle
    at gtkuimanager.c line 2620
  • #17 g_idle_dispatch
    at gmain.c line 3924
  • #18 IA__g_main_context_dispatch
    at gmain.c line 2043
  • #19 g_main_context_iterate
    at gmain.c line 2675
  • #20 IA__g_main_loop_run
    at gmain.c line 2879
  • #21 IA__gtk_clipboard_store
    at gtkclipboard.c line 1883
  • #22 _gtk_clipboard_store_all
    at gtkclipboard.c line 1917
  • #23 IA__gtk_main
    at gtkmain.c line 1050
  • #24 main
    at gedit.c line 566
  • #0 __kernel_vsyscall

Comment 1 Christian Kirbach 2006-08-10 20:12:11 UTC
Bug 165992 has a very similar stack trace. Cause of the crash were too many unrefs.

Good trace, confirming
Comment 2 Christian Kirbach 2006-08-13 17:53:14 UTC
*** Bug 351160 has been marked as a duplicate of this bug. ***
Comment 3 Christian Kirbach 2006-08-13 17:53:26 UTC
an applicatin bug like Bug 165992 ?
Comment 4 Fabio Bonelli 2006-08-14 08:56:28 UTC
*** Bug 351243 has been marked as a duplicate of this bug. ***
Comment 5 Andrew 2006-08-18 15:05:02 UTC
*** Bug 351094 has been marked as a duplicate of this bug. ***
Comment 6 Andrew 2006-08-18 15:10:52 UTC
This only happens when you close gedit with something on the clipboard (sorry if i'm stating the obvious). I get this same stack trace path in Gedit 2.15.6
Comment 7 Paolo Maggi 2006-08-18 17:20:20 UTC
Can you guys explain us how to reproduce this crash step by step?
Comment 8 Andrew 2006-08-18 17:41:17 UTC
Created attachment 71169 [details]
Full backtrace of hello, copy and exit

Paolo,

This works everytime for me:

1) open Gedit (default untitled document appears)
2) type "hello"
3) select "hello" and copy it to the clipboard (ctrl a, ctrl c)
4) close Gedit (close without saving, if you choose save the crash happens
after the file is successfully saved before the crash occurs)

If I don't copy anything to the clipboard (miss out step 3) everything is fine.
The surrounding events seem to be arbitrary, if anything has been copied to the
clipboard before Gedit is closed this crash occurs.

I've attached my own backtraces (of the exact above steps) for good measure,
until the original submitter can confirm this method.
Comment 9 Paolo Maggi 2006-08-18 17:50:32 UTC
I tried with both gedit 2.14.x from Dapper and gedit CVS HEAD, but I cannot reproduce the crash using the step you reported.
Comment 10 Andrew 2006-08-18 18:03:09 UTC
This didn't occur with gedit 2.14.x from Gentoo portage, it only starting occuring upon upgrade of Gnome to 2.15.x.

I just checked gedit out of CVS and this occurs with CVS HEAD. I will emerge gedit 2.14.x from portage again and that should settle whether it's gedit or something else?
Comment 11 Andrew 2006-08-18 18:12:19 UTC
I just compiled gedit 2.14.4 from portage (which compiled fine against all the updated dependencies). gdb confirms it exits normally when I follow the exact same steps.

Seems to be a glitch introduced in gedit 2.15.x. What else can I try?
Comment 12 Paolo Borelli 2006-08-18 19:10:28 UTC
can you try gedit from cvs HEAD, I think I fixed this a couple of days ago: the crash seems related to having G_FATAL_CRITICAL set and an assertion is triggered due to the fact that the window was not disposed correctly.

Another useful piece of info is which plugins you have active. If you disable all plugins the crash goes away?
Comment 13 Andrew 2006-08-18 19:54:10 UTC
Got it!

Systematically disabling and re-enabling the plugins revealed the culprit. This only occurs when the Snippets plugin is enabled.

I'm guessing since the snippets plugin is written in python it opens up a whole new bunch of questions...
Comment 14 Paolo Borelli 2006-08-18 19:56:38 UTC
actually it confirms my point: python plugins cause some 'interesting' reference count issues :)

It should be fixed in cvs head.
Comment 15 Andrew 2006-08-18 20:00:53 UTC
I'm not very familiar with CVS, I only get by with a few cvs commands...

Does "cvs -z3 -d:pserver:anonymous@anoncvs.gnome.org:/cvs/gnome co gedit" checkout the HEAD tag?

Comment 16 Paolo Borelli 2006-08-18 20:07:21 UTC
yes, looks correct [1]

once you have it checked out, you'll need to run ./autogen --prefix=/blah/blah instead of ./configure --prefix=/blah/blah 



[1]: as long as the pserver is still active, since I have an account I use ssh access so I am not sure of which is the pserver status... IIRC with pserver you also need cvs -z3 -d:pserver:anonymous@anoncvs.gnome.org:/cvs/gnome login before the checkout, if asked for a password just press enter.
Comment 17 Andrew 2006-08-18 20:19:56 UTC
I'm sorry to say it still happens in HEAD :|

Could it be one of the python dependencies or glib/gtk python bindings?
Comment 18 Paolo Borelli 2006-08-19 11:35:18 UTC
I managed to reproduce.

It's a refcounting issue: by setting a breakpoint in gedit_window_dispose() you may see that window->priv->manager still has a refcount even when the GeditWindow releases its references. This causes the UIManager to survive the finalization of the window and since finalizing the window instead deatroys the menus and the toolbar, when the survived uimanager tries to update its proxy widgets you get the 
assertion

Gtk-CRITICAL **: gtk_container_foreach: assertion `GTK_IS_CONTAINER (container)' failed


I still have no idea who is holding a ref to the UIManager and why this triggers only when there is something in the clipboard...
Comment 19 Paolo Maggi 2006-08-21 09:44:27 UTC
If this happens only when the snippets plugin is enables, probably the ref is held by the snippets plugin itself... just guessing!
Comment 20 Steve Frécinaux 2006-08-23 08:06:13 UTC
*** Bug 352486 has been marked as a duplicate of this bug. ***
Comment 21 Paolo Maggi 2006-08-25 16:28:49 UTC
Jesse: could you please try to understand what is happening in the snippet plugin?

It would be really nice to fix this for 2.16.
Comment 22 jessevdk@gmail.com 2006-08-26 09:10:53 UTC
Well, I tried to reproduce it but I couldn't. I haven't been able to built gedit with gtk+-2.10 so my guess is that maybe this bug has been introduced by gtkrecent. The fact that it only happens with snippets enabled is then again very weird. I couldn't find anything at first glance in the snippets plugin that might trigger this (as far as I know all the references are dropped).

Not being able to reproduce the bug isn't very handy in trying to solve this one. I'll try get my build environment fixed after the weekend.
Comment 23 Paolo Borelli 2006-08-26 11:12:10 UTC
I've poked at the issue a bit in the following way: in gdb break on window_init and look at the address of priv->manager, let's say it is 0x80eaaa0.

You can then see who refs/unrefs the ui manager with

b g_object_ref if _object==0x80eaaa0
b g_object_unref if _object==0x80eaaa0


With the above I could see that the issue is not caused by someone grabbing an extra ref, the ui manager has a ref of 2 both when putting something in the clipboard (crashing case) and when not using the clipboard. The two refs are owned by the window itself and the python plugin.

The difference in the two cases is the timing at which the refs are released: in the crashing case:

  • #0 g_object_unref
    at gobject.c line 1734
  • #1 gedit_window_dispose
    at gedit-window.c line 135
  • #2 g_object_run_dispose
    at gobject.c line 570
  • #0 g_object_unref
    at gobject.c line 1734
  • #1 pygobject_clear
    at pygobject.c line 969
  • #2 collect
    at Modules/gcmodule.c line 710
  • #3 PyGC_Collect
    at Modules/gcmodule.c line 1193
  • #4 run_gc
    at gedit-python-module.c line 409
  • #5 g_idle_dispatch
    at gmain.c line 3926
  • #6 g_main_context_dispatch
    at gmain.c line 2045
  • #7 g_main_context_iterate
    at gmain.c line 2677
  • #8 g_main_loop_run
    at gmain.c line 2881
  • #9 IA__gtk_clipboard_store
    at gtkclipboard.c line 1883
  • #10 _gtk_clipboard_store_all
    at gtkclipboard.c line 1917
  • #11 IA__gtk_main
    at gtkmain.c line 1050
  • #12 main
    at gedit.c line 568



So I have no idea why this is triggered by the snippets+clipboard combination, but the python gc is run too late.
Comment 24 Paolo Borelli 2006-08-26 14:27:23 UTC
OK, some more analysis and a patch.

The warning/crash has nothing to do with the clipboard nor with snippets specifically: as said above it happens because the python GC runs after the window has been destroyed. This happens when there is something in the clipboard because the clipboard does some magic and keeps the main loop alive, thus the GC is actually run from the queued idle, which however happens after the window has been destroyed. In the normal case (without stuff on the clipboard) this doesn't happen because gedit_python_shutdown() forces the GC to run immediately: as a proof with snippets plugin enabled just open two windows and close one and you'll see the same warning because also in this case we are not shutting python down.
As for not being specific to snippets, it's actually External Tools (the other py plugin that we have which adds menus) that is doing something special preventing the warning: it is calling explicitely manager.ensure_update(), consuming the problematic ui_manager idle.

A first way to solve this specific issue is to call gtk_ui_manager_ensure_update() explicitely in window::dispose() before we drop our ref to the manager, so that we consume all pending updates.

However I prefer a more generic solution, for which I am attaching a patch: I modified gedit_python_garbage_collect() so that it *both* runs the GC immediately and schedules a collection in the idle, then I force the collection in window::dispose() *before* we drop our own refs. This way the GC forces python to drop its ref to the uimanager (and possibly other objects) before we drop our own.
Comment 25 Paolo Borelli 2006-08-26 15:00:45 UTC
Created attachment 71651 [details] [review]
patch

Here is the patch I am committing. Note that there is another important thing I didn't mention above: we need to run the GC both at the start of dispose() and at the end, after we dropped our own references.
Comment 26 Paolo Maggi 2006-08-28 09:40:56 UTC
It seems black magic to me... I wonder why we need all this workaround to make the Python GC to work. How is epiphany dealing with this problems?
Are we sure we don't have broken code with regards to the management of windows life cycle?
Comment 27 Paolo Borelli 2006-08-28 09:58:36 UTC
I don't think it's black magic... well at least not too much: we recently added window::dispose because it's the right place to make sure refcont loops are broken. To do so we first make sure that there are no 'lingering' objectsm then we drop our own references and then we collect again to reap the objects that may have died after our unrefs.

> Are we sure we don't have broken code with regards to the management of windows
> life cycle?

Well I am pretty sure we haven't regressed in this regard: we just run the GC more  than once, but the run scheduked in the idle is still there. However this doesn't mean things are perfect: unfortunately sometimes the window is still not finalized, but this was the case also before the patch.

I have investigated it quite a bit but couldn't come to a solution yet. It seems that it's once again a ref loop issue: if you watch the dispose function with py plugins disabled you'll see that it's run twice, while with python only just once, so there is something that keeps the window alive preventing its finalization.
Comment 28 Diego Escalante Urrelo (not reading bugmail) 2007-07-26 23:36:35 UTC
*** Bug 441678 has been marked as a duplicate of this bug. ***