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 743044 - ewsclient: httpclient: Crashes and deadlocks when destroying SoupSession
ewsclient: httpclient: Crashes and deadlocks when destroying SoupSession
Status: RESOLVED FIXED
Product: gnome-online-accounts
Classification: Core
Component: general
3.14.x
Other All
: Normal normal
: ---
Assigned To: GNOME Online Accounts maintainer(s)
GNOME Online Accounts maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2015-01-16 14:45 UTC by Debarshi Ray
Modified: 2015-01-16 15:27 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
ewsclient: httpclient: Don't crash or deadlock during clean up (3.14 KB, patch)
2015-01-16 15:02 UTC, Debarshi Ray
committed Details | Review

Description Debarshi Ray 2015-01-16 14:45:59 UTC
The way we clean up the session data and complete the operation is broken. It is particularly bad when the _sync API is used.

The user's callback will be invoked before the clean up function because g_simple_async_result_complete_in_idle uses a higher priority than g_idle_add - G_PRIORITY_DEFAULT vs. G_PRIORITY_DEFAULT_IDLE. The _sync API uses a callback that quits the main loop and pops the thread context, and if there is no main loop running for the default context then the clean up will never occur.

This brings us to the next problem. Using g_idle_add sets up the clean up to occur on the default context, while the SoupSession was created to work with the current thread context. This is bad and occasionally leads to a deadlock when destroying the session.

PS: If you are wondering why we do the clean in an idle, then look at these commits:

commit 07f13b1d773b79e5c1049660c154b988b5ff6357
Author: Debarshi Ray <debarshir@gnome.org>
Date:   Wed Dec 5 16:03:01 2012 +0100

    ewsclient: Fix cancellation
    
    Free the AutodiscoverData in an idle handler because soup_session_abort
    invokes ews_client_autodiscover_response_cb. Trying to disconnect the
    GCancellable from a 'cancelled' signal handler will result in a
    deadlock.
    
    Fixes: https://bugzilla.gnome.org/689642

commit b2f94098829232bcb8294d5cefee85d5b9368f2d
Author: Debarshi Ray <debarshir@gnome.org>
Date:   Tue Dec 4 17:46:17 2012 +0100

    httpclient: Fix cancellation
    
    Free the CheckData in an idle handler because soup_session_abort
    invokes http_client_check_response_cb. Trying to disconnect the
    GCancellable from a 'cancelled' signal handler will result in a
    deadlock.
    
    Fixes: https://bugzilla.gnome.org/689642
Comment 1 Debarshi Ray 2015-01-16 14:51:33 UTC
It appears that in some cases (Fedora 20, older GLib ?) it would crash instead of deadlocking:
https://bugzilla.redhat.com/show_bug.cgi?id=1047581
Comment 2 Debarshi Ray 2015-01-16 15:02:40 UTC
Created attachment 294692 [details] [review]
ewsclient: httpclient: Don't crash or deadlock during clean up