Subject: 26.1; gnutls_try_handshake maxes out cpu retrying when server is a bit busy

From: Noam Postavsky <[email-masked]>
Date: Thu, 16 Aug 2018 08:13:40 -0400

Severity: minor

Recently the debbugs.gnu.org server is slow to respond.  I notice this
both when opening bug reports in Firefox, and from Emacs.  However,
Emacs uses 100% cpu while waiting for the server.  I added a message
call in gnutls_try_handshake (see patch below), and got "gnutls
non-fatal: Resource temporarily unavailable, try again. [190088 times]"
in *Messages*.  This was from doing M-x gnus-read-ephemeral-bug-group,
it took 5 or 10 seconds to (eventually successfully) complete.

We should have some kind of delay to avoid sending so many useless
retries.

--- i/src/gnutls.c
+++ w/src/gnutls.c
@@ -65,6 +65,7 @@ your option) any later version.
 
 static bool gnutls_global_initialized;
 
+static char const * emacs_gnutls_strerror (int err);
 static void gnutls_log_function (int, const char *);
 static void gnutls_log_function2 (int, const char *, const char *);
 # ifdef HAVE_GNUTLS3
@@ -558,7 +559,9 @@ gnutls_try_handshake (struct Lisp_Process *proc)
     }
   while (ret < 0
 	 && gnutls_error_is_fatal (ret) == 0
-	 && ! non_blocking);
+	 && ! non_blocking
+         && (message ("gnutls non-fatal: %s", emacs_gnutls_strerror (ret)),
+             true));
 
   proc->gnutls_initstage = GNUTLS_STAGE_HANDSHAKE_TRIED;