Subject: 28.0.50; url-http proxy connection-wait

From: Madhu <[email-masked]>
Date: Thu, 15 Jul 2021 15:25:06 +0530

When accessing https://melpa.org (an nginx webserver) through a
http-proxy (by setting url-proxy-services, say to privoxy), url-http
hangs when parsing headers. apparently the connection is dropped with
emacs master. I'm on this commit on master

GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.16.0, Xaw3d scroll bars) of 2021-06-15
 794ec934a76d0647a72b7be32e20dc5b95e5ec11

#ELISP> (setq url-proxy-services '(("http" . "localhost:8118") ("https" . "localhost:8118")))
ELISP> (url-retrieve-synchronously (url-generic-parse-url "https://melpa.org/"))
#<buffer  *http melpa.org:443*>

And the buffer looks like

#+BEGIN_EXAMPLE

Process melpa.org connection broken by remote peer
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 15 Jul 2021 09:41:12 GMT
Content-Type: text/html; charset=utf-8
Last-Modified: Wed, 10 Feb 2021 23:56:44 GMT
Connection: close
Vary: Accept-Encoding
ETag: W/"602472bc-d92"
Strict-Transport-Security: max-age=15768000
Content-Encoding: gzip
#+END_EXAMPLE

The connection is broken and the "\nProcess HOST connection broken by
remote peer\n" line in the buffer means the spins without parsing the
header.

Now proxied requests are asynchronous.

If I (setf (url-asynchronous url) t) in lisp/url/url.el:
(url-retrieve-internal), as per the appended patch, then eventually
make-network-process gets called with a :nowait t, and the connection
pulls through.

But I'm not sure if this is the right thing or if the problem is
elsewhere as this problem doesn't happen on older emacs - say from
2020-10-15.

Do others see this problem?

[BTW I haven't seen paul eggert on the lists lately, any word if he is
still too busy for emacs?]

diff --git a/lisp/url/url.el b/lisp/url/url.el
index 00c5740cf8..e40a4ecc29 100644
--- a/lisp/url/url.el
+++ b/lisp/url/url.el
@@ -211,8 +211,9 @@ url-retrieve-internal
 	(buffer nil)
 	(asynch (url-scheme-get-property (url-type url) 'asynchronous-p)))
     (if url-using-proxy
-	(setq asynch t
-	      loader #'url-proxy))
+	(progn (setq asynch t
+	             loader #'url-proxy)
+               (setf (url-asynchronous url) t)))
     (if asynch
 	(let ((url-current-object url))
 	  (setq buffer (funcall loader url callback cbargs)))
-- 
2.31.0