[glib-networking] gnutls: fix spurious wakeups from GTlsConnectionGnutlsSource



commit 85051d2d44068a04d60c7852de6d007b330b661a
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Fri Mar 29 19:11:13 2019 -0500

    gnutls: fix spurious wakeups from GTlsConnectionGnutlsSource
    
    I lazily reused the need_finish_handshake variable to signal that it's
    time to stop cranking the handshake context, not realizing there are
    serious consequences to misusing the variable in this way. Now
    need_finish_handshake is always true after a sync handshake. This causes
    telepathy-idle to churn CPU with constant unnecessary wakeups. I didn't
    notice before because WebKit only uses async handshake.
    
    Note this bug meant telepathy-idle would never idle. HAR HAR!
    
    Fixes #69

 tls/gnutls/gtlsconnection-gnutls.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/tls/gnutls/gtlsconnection-gnutls.c b/tls/gnutls/gtlsconnection-gnutls.c
index e9cd798..27bbbcd 100644
--- a/tls/gnutls/gtlsconnection-gnutls.c
+++ b/tls/gnutls/gtlsconnection-gnutls.c
@@ -203,7 +203,7 @@ typedef struct
    * future operations). ever_handshaked indicates that TLS has
    * been successfully negotiated at some point.
    */
-  gboolean need_handshake, need_finish_handshake;
+  gboolean need_handshake, need_finish_handshake, sync_handshake_completed;
   gboolean started_handshake, handshaking, ever_handshaked;
   GMainContext *handshake_context;
   GTask *implicit_handshake;
@@ -2187,7 +2187,7 @@ sync_handshake_thread_completed (GObject      *object,
   g_assert (g_main_context_is_owner (priv->handshake_context));
 
   g_mutex_lock (&priv->op_mutex);
-  priv->need_finish_handshake = TRUE;
+  priv->sync_handshake_completed = TRUE;
   g_mutex_unlock (&priv->op_mutex);
 
   g_main_context_wakeup (priv->handshake_context);
@@ -2204,8 +2204,8 @@ crank_sync_handshake_context (GTlsConnectionGnutls *gnutls,
    * here. So need_finish_handshake should only change on this thread.
    */
   g_mutex_lock (&priv->op_mutex);
-  priv->need_finish_handshake = FALSE;
-  while (!priv->need_finish_handshake && !g_cancellable_is_cancelled (cancellable))
+  priv->sync_handshake_completed = FALSE;
+  while (!priv->sync_handshake_completed && !g_cancellable_is_cancelled (cancellable))
     {
       g_mutex_unlock (&priv->op_mutex);
       g_main_context_iteration (priv->handshake_context, TRUE);


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