[gnome-software/wip/kalev/plugin_loader_cancellable: 2/2] plugin loader: Fix a race with thread cancelling



commit ca1fc8a617ffa34b5dea2f9b5fc8b15aec76b776
Author: Kalev Lember <klember redhat com>
Date:   Tue Dec 12 21:23:29 2017 +0100

    plugin loader: Fix a race with thread cancelling
    
    In our UI code, a common pattern is to cancel async operation
    cancellables in dispose, and then rely on the callbacks to return
    immediately with CANCELLED error code. This pattern makes it easy to
    short circuit when CANCELLED is set and avoid accessing private data
    that has been released in dispose.
    
    Commit fa7216c1284d957acbf266f879a99ffcff06abee regressed this by
    changing the tasks created in the plugin loader to not have
    return-on-cancel set, which causes the async operations to not return
    synchronously, breaking this UI pattern.
    
    This commit changes it back so that plugin loader async operations
    return synchronously when the caller cancels the cancellable.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1467499

 lib/gs-plugin-loader.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 1893bc7..869f818 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1626,6 +1626,7 @@ gs_plugin_loader_job_get_categories_async (GsPluginLoader *plugin_loader,
        /* run in a thread */
        task = g_task_new (plugin_loader, cancellable, callback, user_data);
        g_task_set_task_data (task, helper, (GDestroyNotify) gs_plugin_loader_helper_free);
+       g_task_set_return_on_cancel (task, TRUE);
        g_task_run_in_thread (task, gs_plugin_loader_job_get_categories_thread_cb);
 }
 
@@ -3565,10 +3566,6 @@ gs_plugin_loader_job_process_async (GsPluginLoader *plugin_loader,
        helper = gs_plugin_loader_helper_new (plugin_loader, plugin_job);
        g_task_set_task_data (task, helper, (GDestroyNotify) gs_plugin_loader_helper_free);
 
-       /* let the task cancel itself */
-       g_task_set_check_cancellable (task, FALSE);
-       g_task_set_return_on_cancel (task, FALSE);
-
        /* pre-tokenize search */
        if (action == GS_PLUGIN_ACTION_SEARCH) {
                const gchar *search = gs_plugin_job_get_search (plugin_job);
@@ -3612,6 +3609,7 @@ gs_plugin_loader_job_process_async (GsPluginLoader *plugin_loader,
        }
 
        /* run in a thread */
+       g_task_set_return_on_cancel (task, TRUE);
        g_task_run_in_thread (task, gs_plugin_loader_process_thread_cb);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]