[evolution-data-server/gnome-3-28] Stale connection used after resume



commit fa48afd90821dfaa5c3b0f5d99bf9d2bf7d63379
Author: Milan Crha <mcrha redhat com>
Date:   Thu Apr 26 09:06:01 2018 +0200

    Stale connection used after resume
    
    Turn the backend into offline immediately when the network in unavailable,
    because the 5 second (intentional) delay can be enough to re-establish
    the connection to the Internet, thus keeping the backend online, even when
    it should be disconnected when the network was unavailable.
    
    Reported downstream for EWS backends at:
    https://bugzilla.redhat.com/show_bug.cgi?id=1567572

 src/libebackend/e-backend.c |   44 +++++++++++++++++++++++++++++++-----------
 1 files changed, 32 insertions(+), 12 deletions(-)
---
diff --git a/src/libebackend/e-backend.c b/src/libebackend/e-backend.c
index ebbea1a..31c1be9 100644
--- a/src/libebackend/e-backend.c
+++ b/src/libebackend/e-backend.c
@@ -122,6 +122,28 @@ backend_network_monitor_can_reach_cb (GObject *source_object,
        g_object_unref (backend);
 }
 
+static GSocketConnectable *
+backend_ref_connectable_internal (EBackend *backend)
+{
+       GSocketConnectable *connectable;
+
+       g_return_val_if_fail (E_IS_BACKEND (backend), NULL);
+
+       connectable = e_backend_ref_connectable (backend);
+
+       if (!connectable) {
+               gchar *host = NULL;
+               guint16 port = 0;
+
+               if (e_backend_get_destination_address (backend, &host, &port) && host)
+                       connectable = g_network_address_new (host, port);
+
+               g_free (host);
+       }
+
+       return connectable;
+}
+
 static gboolean
 backend_update_online_state_timeout_cb (gpointer user_data)
 {
@@ -138,7 +160,7 @@ backend_update_online_state_timeout_cb (gpointer user_data)
        if (!backend)
                return FALSE;
 
-       connectable = e_backend_ref_connectable (backend);
+       connectable = backend_ref_connectable_internal (backend);
 
        g_mutex_lock (&backend->priv->update_online_state_lock);
        g_source_unref (backend->priv->update_online_state);
@@ -156,16 +178,6 @@ backend_update_online_state_timeout_cb (gpointer user_data)
                cancellable = NULL;
        }
 
-       if (!connectable) {
-               gchar *host = NULL;
-               guint16 port = 0;
-
-               if (e_backend_get_destination_address (backend, &host, &port) && host)
-                       connectable = g_network_address_new (host, port);
-
-               g_free (host);
-       }
-
        if (connectable == NULL) {
                backend->priv->network_monitor_cancellable = cancellable;
                g_mutex_unlock (&backend->priv->network_monitor_cancellable_lock);
@@ -233,7 +245,15 @@ backend_network_changed_cb (GNetworkMonitor *network_monitor,
                             gboolean network_available,
                             EBackend *backend)
 {
-       backend_update_online_state (backend);
+       if (network_available) {
+               backend_update_online_state (backend);
+       } else {
+               GSocketConnectable *connectable;
+
+               connectable = backend_ref_connectable_internal (backend);
+               e_backend_set_online (backend, !connectable);
+               g_clear_object (&connectable);
+       }
 }
 
 static ESourceAuthenticationResult


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