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 680335 - empathy crashed with SIGSEGV in _tpf_persona_contact_weak_notify_cb()
empathy crashed with SIGSEGV in _tpf_persona_contact_weak_notify_cb()
Status: RESOLVED FIXED
Product: folks
Classification: Platform
Component: Telepathy backend
0.6.x
Other Linux
: Normal critical
: Unset
Assigned To: folks-maint
folks-maint
Depends on:
Blocks:
 
 
Reported: 2012-07-20 18:03 UTC by Bilal Shahid
Modified: 2012-09-05 23:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
stacktrace (4.24 KB, text/plain)
2012-07-20 18:04 UTC, Bilal Shahid
  Details
WIP work to fix contact weak notification (1.30 KB, patch)
2012-07-30 08:20 UTC, Philip Withnall
accepted-commit_now Details | Review
Fix contact weak notification (13.98 KB, patch)
2012-09-02 20:29 UTC, Philip Withnall
none Details | Review

Description Bilal Shahid 2012-07-20 18:03:26 UTC
I did not do anything with the empathy client at the time of the crash.

ProblemType: Crash
DistroRelease: Ubuntu 12.10
Package: empathy 3.5.3-0ubuntu1
ProcVersionSignature: Ubuntu 3.5.0-4.4-generic 3.5.0-rc6
Uname: Linux 3.5.0-4-generic x86_64
Comment 1 Bilal Shahid 2012-07-20 18:04:06 UTC
Created attachment 219340 [details]
stacktrace
Comment 2 Guillaume Desmottes 2012-07-23 07:34:55 UTC
Looks like it crashes in Folks.
Comment 3 Bilal Shahid 2012-07-23 12:34:33 UTC
originally reported at https://bugs.launchpad.net/ubuntu/+source/empathy/+bug/1024217
Comment 4 Jeremy Whiting 2012-07-23 17:51:07 UTC
Bilal, what version of folks do you have installed?
Comment 5 Philip Withnall 2012-07-23 23:31:36 UTC
Might be bug #675141. That was fixed in 0.7.1.
Comment 6 Martin Pitt 2012-07-24 18:53:31 UTC
I had folks 0.7.2.2 installed at that time, and still have that version.
Comment 7 Guillaume Desmottes 2012-07-28 09:57:00 UTC
I'm experiencing this crash a lot here at guadec with folks 0.7.2.2



(lt-empathy:32671): GLib-GObject-WARNING **: g_object_weak_unref: couldn't find weak ref 0x7ffff701d3e0(0x3f3a000)

Program received signal SIGTRAP, Trace/breakpoint trap.
0x00007ffff3e561e9 in g_logv (log_domain=0x7ffff418704f "GLib-GObject", log_level=G_LOG_LEVEL_WARNING, 
    format=0x7ffff4187e90 "%s: couldn't find weak ref %p(%p)", args1=0x7fffffffcd68) at gmessages.c:758
758			G_BREAKPOINT ();
(gdb)  bt
  • #0 g_logv
  • #1 g_log
  • #2 g_object_weak_unref
    at gobject.c line 2561
  • #3 tpf_persona_finalize
    at tpf-persona.c line 4664
  • #4 g_object_unref
    at gobject.c line 3023
  • #5 _tpf_persona_store_contact_weak_notify_cb
    at tpf-persona-store.c line 3228
  • #6 __tpf_persona_store_contact_weak_notify_cb_gweak_notify
    at tpf-persona-store.c line 1479
  • #7 weak_refs_notify
    at gobject.c line 2469
  • #8 g_data_set_internal
    at gdataset.c line 417
  • #9 g_datalist_id_set_data_full
    at gdataset.c line 680
  • #10 g_object_real_dispose
    at gobject.c line 1012
  • #11 tp_contact_dispose
    at contact.c line 846
  • #12 g_object_unref
    at gobject.c line 2986
  • #13 g_ptr_array_foreach
    at garray.c line 1434
  • #14 ptr_array_free
    at garray.c line 1063
  • #15 g_ptr_array_unref
    at garray.c line 1014
  • #16 contacts_changed_head_ready
    at connection-contact-list.c line 130
  • #17 process_queued_contacts_changed
    at connection-contact-list.c line 187
  • #18 contacts_changed_cb
    at connection-contact-list.c line 218
  • #19 _tp_cli_connection_interface_contact_list_invoke_callback_for_contacts_changed_with_id
    at _gen/tp-cli-connection-body.h line 11115
  • #20 tp_proxy_signal_invocation_run
    at proxy-signals.c line 268
  • #21 g_idle_dispatch
    at gmain.c line 4777
  • #22 g_main_dispatch
    at gmain.c line 2691
  • #23 g_main_context_dispatch
    at gmain.c line 3195
  • #24 g_main_context_iterate
    at gmain.c line 3266
  • #25 g_main_context_iteration
    at gmain.c line 3327
  • #26 g_application_run
    at gapplication.c line 1607
  • #27 main
    at empathy.c line 847

Comment 8 Guillaume Desmottes 2012-07-28 10:00:49 UTC
Looks like the connection is salut, thay may explain why I'm experiencing this crash much more here.
Comment 9 Philip Withnall 2012-07-30 08:20:53 UTC
Created attachment 219868 [details] [review]
WIP work to fix contact weak notification

So here’s the order of events causing this:
 1. The TpContact is finalised, triggering its weak notifications. Before the weak notification callbacks are called, the list of weak notifications is cleared (so g_object_weak_unref() will print a warning).
 2. _contact_weak_notify_cb() in Tpf.PersonaStore is called first, and it removes the Persona (corresponding to the TpContact) from various maps. It turns out that the Tpf.PersonaStore holds the last reference to the Persona, so at the end of _contact_weak_notify_cb(), the Persona is finalised.
 3. The finalise function of the Persona checks whether Persona.contact != null. This check is true, because the Persona’s _contact_weak_notify_cb() hasn’t yet been called by GLib, since we’re still in a descendent call of the Tpf.PersonaStore’s _contact_weak_notify_cb().
 4. As a result, the Persona calls g_object_weak_unref() on its TpContact, and GLib gets unhappy.

I see two ways to fix this:
 A. Extend the lifetime of the Persona a little longer so that its _contact_weak_notify_cb() is correctly called before the Persona is finalised. This is what the attached patch does, in a horrible and hacky way.
 B. Explicitly clear the Persona.contact from the Tpf.PersonaStore’s _contact_weak_notify_cb() so that finalisation of the Persona from within _contact_weak_notify_cb() succeeds.

Option A seems a little cleaner than option B (to me), but both seem fairly nasty and suggestions are welcome for better solutions. Otherwise, I can tidy up this patch (add a NEWS entry, expand the commenting, etc.) and commit it.
Comment 10 Guillaume Desmottes 2012-08-28 13:19:34 UTC
Review of attachment 219868 [details] [review]:

Looks good to me. I agree it's not the finest piece of code ever but sometimes that's the easiest way to fix such nasty bug.
Comment 11 Philip Withnall 2012-08-28 21:52:59 UTC
I’m wondering if it’s perhaps a GLib bug that g_object_weak_unref() explodes if called from within a weak notification for the same object. I’ll ask around a bit and see if a better solution can be found. If that fails, I’ll commit this patch.
Comment 12 Philip Withnall 2012-09-02 20:29:01 UTC
Created attachment 223214 [details] [review]
Fix contact weak notification

https://www.gitorious.org/folks/folks/commits/680335-contact-weak-notification-attempt2

Here’s a much better attempt. desrt suggested using a GWeakRef in Tpf.Persona to handle setting Tpf.Persona._contact to null when the TpContact is destroyed. This eliminates the race condition.

The code’s a bit messy because Tpf.Persona.contact doesn’t return a strong ref., but there’s nothing we can do about that until folks next breaks API.

This also includes some associated fixes to ensure folks uses a strong ref. for TpContacts when performing operations on them (e.g. setting their properties).
Comment 13 Jeremy Whiting 2012-09-05 22:52:13 UTC
The code is not that bad, and is documented where it should be changed later on.  If this fixes the bug I say ship it.