Subject: Re: bug#25060: gnutls: asynchronous spurious "fatal error"

From: Lars Ingebrigtsen <[email-masked]>
Date: Wed, 25 Jan 2017 00:17:58 +0100

Andy Wingo <[email-masked]> writes:

>     (url-retrieve "https://www.gnu.org/"
>                   #'(lambda (status)
>                       (message "success")))

[...]

> And then, after a couple seconds:
>
>     gnutls.c: [0] (Emacs) fatal error: The TLS connection was non-properly terminated.

Yes, it just means that the peer ended the connection.  I think gnutls.c
shouldn't say anything in that case -- any sentinels get the proper
callback and stuff, and as information it's pretty worthless for the
user.

I'm installing the following patch, but if there's any disagreement
here, we can discuss further...

diff --git a/src/gnutls.c b/src/gnutls.c
index 735d2e3..6fa0e10 100644
--- a/src/gnutls.c
+++ b/src/gnutls.c
@@ -582,8 +582,15 @@ emacs_gnutls_handle_error (gnutls_session_t session, int err)
 
   if (gnutls_error_is_fatal (err))
     {
+      int level = 1;
+      /* Mostly ignore "The TLS connection was non-properly
+	 terminated" message which just means that the peer closed the
+	 connection.  */
+      if (err == GNUTLS_E_PREMATURE_TERMINATION)
+	level = 3;
+
+      GNUTLS_LOG2 (level, max_log_level, "fatal error:", str);
       ret = 0;
-      GNUTLS_LOG2 (1, max_log_level, "fatal error:", str);
     }
   else
     {

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no