[glib] gio/tests: Prevent hangs and aborts in socket-listener



commit 7d9816934e6a233369a2df1282a49d1549d9fa0f
Author: Ross Lagerwall <rosslagerwall gmail com>
Date:   Sun Nov 30 22:17:51 2014 +0000

    gio/tests: Prevent hangs and aborts in socket-listener
    
    Fix two problems:
    1) If g_socket_service_stop is called before the accept call is requeued,
    then the reference count won't decrease and this code will hang forever:
      while (G_OBJECT (service)->ref_count == ref_count)
        g_main_context_iteration (NULL, TRUE);
    
    2) Sometimes the testcase fails (maybe 1 in 200 times for me):
    GLib-GIO:ERROR:socket-listener.c:73:connection_cb: assertion failed
    (G_OBJECT (service)->ref_count == 2): (3 == 2)
    Aborted (core dumped)
    
    The problem is that depending on ordering, cancellation of the async
    listener can require further main context iterations before it releases
    the reference on the socket service. Furthermore, in some cases, it
    requires at least one iteration.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=712570

 gio/tests/socket-listener.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/gio/tests/socket-listener.c b/gio/tests/socket-listener.c
index b741b8e..98e3396 100644
--- a/gio/tests/socket-listener.c
+++ b/gio/tests/socket-listener.c
@@ -99,7 +99,6 @@ test_threaded_712570 (void)
   GMainLoop *loop;
   GSocketClient *client;
   GError *error = NULL;
-  int ref_count;
 
   g_test_bug ("712570");
 
@@ -135,11 +134,13 @@ test_threaded_712570 (void)
 
   /* Stop the service and then wait for it to asynchronously cancel
    * its outstanding accept() call (and drop the associated ref).
+   * At least one main context iteration is required in some circumstances
+   * to ensure that the cancellation actually happens.
    */
-  ref_count = G_OBJECT (service)->ref_count;
   g_socket_service_stop (G_SOCKET_SERVICE (service));
-  while (G_OBJECT (service)->ref_count == ref_count)
+  do
     g_main_context_iteration (NULL, TRUE);
+  while (G_OBJECT (service)->ref_count > 3);
 
   /* Drop our ref, then unlock the mutex and wait for the service to be
    * finalized. (Without the fix for 712570 it would hang forever here.)


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