[jsonrpc-glib/jsonrpc-glib-3-26] client: handle client closing more gracefully



commit 8f3a97275ababfdda4371d1cf997c57ff2f5a4b6
Author: Christian Hergert <chergert redhat com>
Date:   Tue Sep 12 15:10:12 2017 -0700

    client: handle client closing more gracefully
    
    We might get an error while closing due to pending operations, but we
    always cancel the in-flight operations. This changes things to pass the
    the failure up instead of a g_warning().

 src/jsonrpc-client.c |   10 ++++++----
 tests/test-stress.c  |    7 ++++---
 2 files changed, 10 insertions(+), 7 deletions(-)
---
diff --git a/src/jsonrpc-client.c b/src/jsonrpc-client.c
index 0ced9da..e758345 100644
--- a/src/jsonrpc-client.c
+++ b/src/jsonrpc-client.c
@@ -1138,7 +1138,7 @@ jsonrpc_client_close (JsonrpcClient  *self,
 {
   JsonrpcClientPrivate *priv = jsonrpc_client_get_instance_private (self);
   g_autoptr(GHashTable) invocations = NULL;
-  g_autoptr(GError) close_error = NULL;
+  gboolean ret;
 
   g_return_val_if_fail (JSONRPC_IS_CLIENT (self), FALSE);
   g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
@@ -1151,8 +1151,10 @@ jsonrpc_client_close (JsonrpcClient  *self,
   if (!g_cancellable_is_cancelled (priv->read_loop_cancellable))
     g_cancellable_cancel (priv->read_loop_cancellable);
 
-  if (!g_io_stream_close (priv->io_stream, cancellable, &close_error))
-    g_warning ("Failure closing stream: %s", close_error->message);
+  /* This can fail from "pending operations", but we will always cancel
+   * our tasks. But we should let the caller know either way.
+   */
+  ret = g_io_stream_close (priv->io_stream, cancellable, error);
 
   /*
    * Closing the input stream will fail, so just rely on the callback
@@ -1177,7 +1179,7 @@ jsonrpc_client_close (JsonrpcClient  *self,
         g_task_return_error (task, g_error_copy (local_error));
     }
 
-  return TRUE;
+  return ret;
 }
 
 /**
diff --git a/tests/test-stress.c b/tests/test-stress.c
index f612b4c..b3aed22 100644
--- a/tests/test-stress.c
+++ b/tests/test-stress.c
@@ -65,9 +65,10 @@ server_handle_reply_cb (JsonrpcClient *client,
   if (n_ops == 0)
     {
       LOG ("server: closing client stream");
-      r = jsonrpc_client_close (client, NULL, &error);
-      g_assert_no_error (error);
-      g_assert_cmpint (r, ==, 1);
+      /* Close might error, but the tasks are always
+       * flushed and cancelled.
+       */
+      jsonrpc_client_close (client, NULL, NULL);
     }
 }
 


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