Subject: bug#32658: gnutls + non-blocking url-retrieve

From: [email-masked]
Date: Wed, 03 Oct 2018 16:15:31 +0200

Eli Zaretskii <[email-masked]> writes:

>> From: [email-masked]
>> Date: Sun, 30 Sep 2018 23:33:10 +0200
>> 
>> 1.) I needed to revert to gnutls 3.5.19, the mingw64 build from the
>> gitlab ci build seems to have a working gnutls-cli tools on windows 10.
>> the gitlab builds for 3.6.3 and 3.6.4 seems to have another bug
>> (error code -53) in the gnutls-cli command.
>> 
>> so only gnutls 3.5.19 have a working gnutls-cli. i installed this version in emacs 26.1
>> 
>> 2.) testing gnutls stream
>> using open-gnutls-stream directly gives me a correct tls connection but
>> eww still fails to load the site.
>> 
>> when I change url-open-stream in url/url-gw.el to:
>> 			  (open-network-stream
>> 			   name buffer host service
>> 			   :type gw-method
>> 			   ;; Use non-blocking socket if we can.
>>                           :nowait nil))
>> 
>> I finally can open lwn.net in eww.
>> 
>> so something seems to be wrong possible with blocking/non-blocking
>> network access.
>> 
>> any ideas?
>
> Thanks for the info.

so what happens in process.c:3669 in function connect_network_socket when gnutls_boot
returns with GNUTLS_STAGE_HANDSHAKE_TRIED and boot(error code) will
error GNUTLS_E_AGAIN (and
not even considered, as far as I understand the code).

I think this is what happens in may case.
gnutls_boot calls gnutls_try_handshake (gnutls.c:595) and the do/while loops returns after 3 times (what
I don't understand is: why is this happening, can maybe_quit() somewho break the loop?)

  do
    {
      ret = gnutls_handshake (state);
      emacs_gnutls_handle_error (state, ret);
      maybe_quit ();
    }
  while (ret < 0
	 && gnutls_error_is_fatal (ret) == 0
	 && ! non_blocking);

//HINT: maybe save emacs_gnutls_handle_error return value and check this
instead of calling gnutls_error_is_fatal again?

  proc->gnutls_initstage = GNUTLS_STAGE_HANDSHAKE_TRIED;

  if (ret == GNUTLS_E_SUCCESS)
    {
      /* Here we're finally done.  */
      proc->gnutls_initstage = GNUTLS_STAGE_READY;
    }
  else
    {
      /* check_memory_full (gnutls_alert_send_appropriate (state, ret));  */
    }
  return ret;

so what do you think?