Fix main thread deadlock issue 55/301055/1 accepted/tizen/7.0/unified/20231109.024726
authorWootak Jung <wootak.jung@samsung.com>
Tue, 24 Oct 2023 22:45:27 +0000 (07:45 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Tue, 7 Nov 2023 23:45:50 +0000 (08:45 +0900)
GSource should be removed by calling g_source_destroy() not g_source_remove().
Using g_source_remove(), wrong GSources in the main context can be removed.

48492 [pid 23543] writev(4, [{iov_base="\3", iov_len=1}, {iov_base="CAPI_NETWORK_DNSSD\0", iov_len=19},
 {iov_base="dns-sd.c: __remove_service_resolve_socket(1369) > Remove DNSServiceResolve socket\0", iov_len=82}], 3 <unfinished ...>
48517 [pid 23543] write(2, "\n(process:23543): GLib-CRITICAL **: 13:35:03.291: Source ID 1 was not found
 when attempting to remove it\n", 105 <unfinished ...>

Change-Id: I2e2f8accba980073e39a70e9a39ef11b32086314
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
src/dns-sd/dns-sd.c

index c3abd4342cb0df368b68adf4de08b24d9132ea74..438b5742b660b98aaaa78639b70bd9436d5afb7d 100644 (file)
@@ -1113,7 +1113,9 @@ EXPORT_API int dnssd_deregister_local_service(dnssd_service_h local_service)
        }
 
        if (local_handle->watch_id > 0) {
-               g_source_remove(local_handle->watch_id);
+               GMainContext *context = g_main_context_get_thread_default();
+               GSource *source = g_main_context_find_source_by_id(context, local_handle->watch_id);
+               g_source_destroy(source);
                local_handle->watch_id = 0;
        }
 
@@ -1131,8 +1133,11 @@ static gboolean __remove_service_getaddrinfo_socket(gpointer user_data)
        DNSSD_LOCK;
        DNSSD_LOGD("Remove DNSServiceGetAddrInfo socket");
        dnssd_handle_s *local_handle = user_data;
-       if (local_handle->watch_id > 0)
-               g_source_remove(local_handle->watch_id);
+       if (local_handle->watch_id > 0) {
+               GMainContext *context = g_main_context_get_thread_default();
+               GSource *source = g_main_context_find_source_by_id(context, local_handle->watch_id);
+               g_source_destroy(source);
+       }
        DNSServiceRefDeallocate(local_handle->sd_ref);
        local_handle->watch_id = 0;
        local_handle->sd_ref = NULL;
@@ -1364,8 +1369,11 @@ static gboolean __remove_service_resolve_socket(gpointer user_data)
        DNSSD_LOCK;
        DNSSD_LOGD("Remove DNSServiceResolve socket");
        resolve_reply_data *resolve_data = user_data;
-       if (resolve_data->watch_id > 0)
-               g_source_remove(resolve_data->watch_id);
+       if (resolve_data->watch_id > 0) {
+               GMainContext *context = g_main_context_get_thread_default();
+               GSource *source = g_main_context_find_source_by_id(context, resolve_data->watch_id);
+               g_source_destroy(source);
+       }
        DNSServiceRefDeallocate(resolve_data->sd_ref);
        resolve_data->watch_id = 0;
        resolve_data->sd_ref = NULL;
@@ -1394,8 +1402,7 @@ static void __dnssd_resolve_reply_cb(DNSServiceRef sd_ref, unsigned int flags,
                        host_name, resolve_data->service_name, fullname,
                        (const char *) txt_record, txt_len, port);
 
-       g_idle_add_full(G_PRIORITY_HIGH, __remove_service_resolve_socket,
-                                       resolve_data, NULL);
+       __remove_service_resolve_socket(resolve_data);
        DNSSD_UNLOCK;
 }
 
@@ -1688,8 +1695,11 @@ static int __get_valid_browsing_handle(dnssd_service_h dnssd_service, dnssd_hand
 
 void __destroy_browsing_handle(dnssd_handle_s *browsing_handle)
 {
-       if (browsing_handle->watch_id > 0)
-               g_source_remove(browsing_handle->watch_id);
+       if (browsing_handle->watch_id > 0) {
+               GMainContext *context = g_main_context_get_thread_default();
+               GSource *source = g_main_context_find_source_by_id(context, browsing_handle->watch_id);
+               g_source_destroy(source);
+       }
 
        DNSServiceRefDeallocate(browsing_handle->sd_ref);
        browsing_handle->sd_ref = NULL;