[gnome-builder] jsonrpc: don't allow stream failures to cause us to fail



commit b259436eb9d47066d93a6813347f9ea6190f4e58
Author: Christian Hergert <chergert redhat com>
Date:   Sun Oct 30 15:38:25 2016 -0700

    jsonrpc: don't allow stream failures to cause us to fail
    
    If we fail to close a stream, we don't want to get into a position where
    we leak our incomplete tasks. So simply ignore stream close failures and
    let the streams cleanup however they like.

 contrib/jsonrpc-glib/jsonrpc-client.c |   32 +++++++++++++++-----------------
 1 files changed, 15 insertions(+), 17 deletions(-)
---
diff --git a/contrib/jsonrpc-glib/jsonrpc-client.c b/contrib/jsonrpc-glib/jsonrpc-client.c
index 7b40461..b826749 100644
--- a/contrib/jsonrpc-glib/jsonrpc-client.c
+++ b/contrib/jsonrpc-glib/jsonrpc-client.c
@@ -1005,9 +1005,6 @@ jsonrpc_client_close (JsonrpcClient  *self,
 {
   JsonrpcClientPrivate *priv = jsonrpc_client_get_instance_private (self);
   g_autoptr(GHashTable) invocations = NULL;
-  g_autoptr(GError) local_error = NULL;
-  GHashTableIter iter;
-  GTask *task;
 
   g_return_val_if_fail (JSONRPC_IS_CLIENT (self), FALSE);
   g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
@@ -1021,27 +1018,28 @@ jsonrpc_client_close (JsonrpcClient  *self,
     g_cancellable_cancel (priv->read_loop_cancellable);
 
   if (!g_output_stream_is_closed (G_OUTPUT_STREAM (priv->output_stream)))
-    {
-      if (!g_output_stream_close (G_OUTPUT_STREAM (priv->output_stream), cancellable, error))
-        return FALSE;
-    }
+    g_output_stream_close (G_OUTPUT_STREAM (priv->output_stream), cancellable, NULL);
 
   if (!g_input_stream_is_closed (G_INPUT_STREAM (priv->input_stream)))
-    {
-      if (!g_input_stream_close (G_INPUT_STREAM (priv->input_stream), cancellable, error))
-        return FALSE;
-    }
+    g_input_stream_close (G_INPUT_STREAM (priv->input_stream), cancellable, NULL);
 
   invocations = g_steal_pointer (&priv->invocations);
   priv->invocations = g_hash_table_new_full (NULL, NULL, NULL, g_object_unref);
 
-  local_error = g_error_new_literal (G_IO_ERROR,
-                                     G_IO_ERROR_CLOSED,
-                                     "The underlying stream was closed");
+  if (g_hash_table_size (invocations) > 0)
+    {
+      g_autoptr(GError) local_error = NULL;
+      GTask *task;
+      GHashTableIter iter;
 
-  g_hash_table_iter_init (&iter, invocations);
-  while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&task))
-    g_task_return_error (task, g_error_copy (local_error));
+      local_error = g_error_new_literal (G_IO_ERROR,
+                                         G_IO_ERROR_CLOSED,
+                                         "The underlying stream was closed");
+
+      g_hash_table_iter_init (&iter, invocations);
+      while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&task))
+        g_task_return_error (task, g_error_copy (local_error));
+    }
 
   return TRUE;
 }


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