From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#49449: 28: TLS connection never gets to "open" stage Date: Mon, 12 Jul 2021 16:57:00 +0200 Message-ID: <07ECB92A-D6FF-43FF-989D-5F34918F180F@acm.org> References: <87lf6h3nj0.fsf@gnus.org> <22155A42-4A01-4EF1-80BC-B9CDE31ED0B1@acm.org> <87o8bdt180.fsf@gnus.org> <875yxip21h.fsf@gnus.org> <875yxinm2e.fsf@gnus.org> <83sg0matjg.fsf@gnu.org> <6FC06816-48AF-4853-92A9-B0E6BA424533@acm.org> <83pmvqarua.fsf@gnu.org> <580679E8-B94D-4B46-A0CB-CA52B9D535EB@acm.org> <83fswlbb1c.fsf@gnu.org> <23DD5CB6-5035-4C19-91B8-548F0B47E9FC@acm.org> <83eec5b1jb.fsf@gnu.org> <837dhwc2sf.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.21\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_93DD7399-6D1B-4332-9BC7-9937FCCD9906" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30973"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 49449@debbugs.gnu.org, larsi@gnus.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jul 12 17:06:00 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m2xVP-0007r1-Ra for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 12 Jul 2021 17:06:00 +0200 Original-Received: from localhost ([::1]:53042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m2xVO-00005k-QC for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 12 Jul 2021 11:05:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2xOg-0005fP-A6 for bug-gnu-emacs@gnu.org; Mon, 12 Jul 2021 10:59:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55328) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m2xOg-000423-1L for bug-gnu-emacs@gnu.org; Mon, 12 Jul 2021 10:59:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m2xOg-0005St-19 for bug-gnu-emacs@gnu.org; Mon, 12 Jul 2021 10:59:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Jul 2021 14:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49449 X-GNU-PR-Package: emacs Original-Received: via spool by 49449-submit@debbugs.gnu.org id=B49449.162610191420965 (code B ref 49449); Mon, 12 Jul 2021 14:59:01 +0000 Original-Received: (at 49449) by debbugs.gnu.org; 12 Jul 2021 14:58:34 +0000 Original-Received: from localhost ([127.0.0.1]:38641 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m2xOE-0005S4-AH for submit@debbugs.gnu.org; Mon, 12 Jul 2021 10:58:34 -0400 Original-Received: from mail70c50.megamailservers.eu ([91.136.10.80]:52436) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m2xOB-0005Ru-IV for 49449@debbugs.gnu.org; Mon, 12 Jul 2021 10:58:32 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1626101908; bh=xKg/8UYvlDDoRQRjO1sZ+Op8wtWoFjgxGSjmtkai8t0=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=dTDIJhGni6vh8A19t9L/KGnaPlB/ak3+c+9EjTA0z409Gk8CSOHy8U0cPEATlssG9 AGns8jYkjdc3Su5Z363V68uE18A2+LTvXYOb5nt/JU9IWauB5klV5TXkM0tHU5iMWq miIWNfwVWUgMPUuh9h1HU93Ecrsw82aA02SGz2qQ= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.0.4] (c188-150-171-71.bredband.tele2.se [188.150.171.71]) (authenticated bits=0) by mail70c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 16CEwQlA011638; Mon, 12 Jul 2021 14:58:27 +0000 In-Reply-To: <837dhwc2sf.fsf@gnu.org> X-Mailer: Apple Mail (2.3445.104.21) X-CTCH-RefID: str=0001.0A742F27.60EC5894.008A, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=G/ti7Os5 c=1 sm=1 tr=0 a=SF+I6pRkHZhrawxbOkkvaA==:117 a=SF+I6pRkHZhrawxbOkkvaA==:17 a=M51BFTxLslgA:10 a=mDV3o1hIAAAA:8 a=01x6aIaDnKLFDTL6cJMA:9 a=CjuIK1q_8ugA:10 a=l8CNaK9fnQMVcNqST9YA:9 a=B2y7HmGcmWMA:10 a=_FVE-zBwftR9WsbkzFJk:22 X-Origin-Country: SE X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:209827 Archived-At: --Apple-Mail=_93DD7399-6D1B-4332-9BC7-9937FCCD9906 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 11 juli 2021 kl. 17.01 skrev Eli Zaretskii : >> I still favour the less intrusive patch posted previously (adding a = condition at line 5235) since it avoids duplication; there is already = far too much of that in the code (everything seems to be done in at = least two places). The code is obviously in the need of restructuring, = but we shouldn't conflate that effort with fixing this specific bug. >=20 > I tend to agree. Attached is the patch that I intend to push if there are no objections. = The actual change is the same as before and I anticipate no trouble = arising from it but tests are usually more fragile. This issue could very well be the root cause of or at least connected to = other bugs: maybe bug#36017 or bug#34341? In any case it's good to see = it fixed; it annoyed me (with GNU ELPA in particular) for quite some = time and the various unsatisfactory workarounds suggested each time this = came up (such as using HTTP instead of HTTPS) are no longer required. --Apple-Mail=_93DD7399-6D1B-4332-9BC7-9937FCCD9906 Content-Disposition: attachment; filename=0001-Block-TLS-handshake-until-TCP-connection-established.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Block-TLS-handshake-until-TCP-connection-established.patch" Content-Transfer-Encoding: quoted-printable =46rom=2088b0b7e0dd0daec88eab7dde0c9bd3263d8b52de=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Mon,=2012=20Jul=202021=2013:58:28=20+0200=0A= Subject:=20[PATCH]=20Block=20TLS=20handshake=20until=20TCP=20connection=20= established=0A=0AIf=20a=20TLS=20handshake=20is=20attempted=20before=20= the=20completion=20of=20an=0Aasynchronous=20TCP=20connection=20has=20= been=20ascertained,=20our=20local=20state=20will=0Anot=20be=20set=20up=20= correctly=20for=20further=20progress=20and=20the=20sentinel=20"open"=0A= event=20will=20never=20be=20sent.=20=20This=20can=20occur=20if=20= sufficient=20time=20passes=0Aafter=20the=20initiation=20of=20an=20async=20= TCP=20connection=20so=20that=20by=20the=20time=0A= `wait_reading_process_output`=20is=20called,=20the=20connection=20has=20= already=0Abeen=20established=20on=20the=20TCP=20level.=0A=0AThis=20= somewhat=20timing-sensitive=20bug=20has=20plagued=20HTTPS=20connections=20= on=0Asome=20platforms,=20notably=20macOS,=20for=20a=20long=20time=20= (bug#49449).=0A=0A*=20src/process.c=20(wait_reading_process_output):=20= Gate=20the=20TLS=20handshake=0Aby=20the=20NON_BLOCKING_CONNECT_FD=20= flag.=20=20The=20flag=20will=20be=20cleared=20as=20soon=0Aas=20the=20TCP=20= socket=20is=20found=20to=20be=20writable.=0A*=20= test/src/process-tests.el=20(process-async-https-with-delay):=0ANew=20= test.=0A---=0A=20src/process.c=20=20=20=20=20=20=20=20=20=20=20=20=20|=20= =205=20++++-=0A=20test/src/process-tests.el=20|=2030=20= ++++++++++++++++++++++++++++++=0A=202=20files=20changed,=2034=20= insertions(+),=201=20deletion(-)=0A=0Adiff=20--git=20a/src/process.c=20= b/src/process.c=0Aindex=20b8c3e4ecfb..c3186eed75=20100644=0A---=20= a/src/process.c=0A+++=20b/src/process.c=0A@@=20-5232,7=20+5232,10=20@@=20= wait_reading_process_output=20(intmax_t=20time_limit,=20int=20nsecs,=20= int=20read_kbd,=0A=20#ifdef=20HAVE_GNUTLS=0A=20=09=09/*=20Continue=20TLS=20= negotiation.=20*/=0A=20=09=09if=20(p->gnutls_initstage=20=3D=3D=20= GNUTLS_STAGE_HANDSHAKE_TRIED=0A-=09=09=20=20=20=20&&=20= p->is_non_blocking_client)=0A+=09=09=20=20=20=20&&=20= p->is_non_blocking_client=0A+=09=09=20=20=20=20/*=20Don't=20proceed=20= until=20we=20have=20established=20a=20connection.=20*/=0A+=09=09=20=20=20= =20&&=20!(fd_callback_info[p->outfd].flags=0A+=09=09=09=20&=20= NON_BLOCKING_CONNECT_FD))=0A=20=09=09=20=20{=0A=20=09=09=20=20=20=20= gnutls_try_handshake=20(p);=0A=20=09=09=20=20=20=20= p->gnutls_handshakes_tried++;=0Adiff=20--git=20= a/test/src/process-tests.el=20b/test/src/process-tests.el=0Aindex=20= 1774f2fc74..9bab523708=20100644=0A---=20a/test/src/process-tests.el=0A= +++=20b/test/src/process-tests.el=0A@@=20-28,6=20+28,7=20@@=0A=20= (require=20'puny)=0A=20(require=20'subr-x)=0A=20(require=20'dns)=0A= +(require=20'url-http)=0A=20=0A=20;;=20Timeout=20in=20seconds;=20the=20= test=20fails=20if=20the=20timeout=20is=20reached.=0A=20(defvar=20= process-test-sentinel-wait-timeout=202.0)=0A@@=20-916,5=20+917,34=20@@=20= process-sentinel-interrupt-event=0A=20=20=20=20=20=20=20;;=20...and=20= the=20change=20description=20should=20be=20"interrupt".=0A=20=20=20=20=20= =20=20(should=20(equal=20'("interrupt\n")=20events)))))=0A=20=0A= +(ert-deftest=20process-async-https-with-delay=20()=0A+=20=20"Bug#49449:=20= asynchronous=20TLS=20connection=20with=20delayed=20completion."=0A+=20=20= (skip-unless=20(and=20internet-is-working=20(gnutls-available-p)))=0A+=20= =20(let*=20((status=20nil)=0A+=20=20=20=20=20=20=20=20=20(buf=20= (url-http=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20#s(url=20= "https"=20nil=20nil=20"elpa.gnu.org"=20nil=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= "/packages/archive-contents"=20nil=20nil=20t=20silent=20t=20t)=0A+=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20(lambda=20(s)=20(setq=20status=20= s))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20'(nil)=20nil=20= 'tls)))=0A+=20=20=20=20(unwind-protect=0A+=20=20=20=20=20=20=20=20(progn=0A= +=20=20=20=20=20=20=20=20=20=20;;=20Busy-wait=20for=201=20s=20to=20allow=20= for=20the=20TCP=20connection=20to=20complete.=0A+=20=20=20=20=20=20=20=20= =20=20(let=20((delay=201.0)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20(t0=20(float-time)))=0A+=20=20=20=20=20=20=20=20=20=20=20=20(while=20= (<=20(float-time)=20(+=20t0=20delay))))=0A+=20=20=20=20=20=20=20=20=20=20= ;;=20Wait=20for=20the=20entire=20operation=20to=20finish.=0A+=20=20=20=20= =20=20=20=20=20=20(let=20((limit=204.0)=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20(t0=20(float-time)))=0A+=20=20=20=20=20=20=20=20=20=20=20= =20(while=20(and=20(null=20status)=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20(<=20(float-time)=20(+=20t0=20= limit)))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20(sit-for=200.1)))=0A= +=20=20=20=20=20=20=20=20=20=20(should=20status)=0A+=20=20=20=20=20=20=20= =20=20=20(should-not=20(assq=20:error=20status))=0A+=20=20=20=20=20=20=20= =20=20=20(should=20buf)=0A+=20=20=20=20=20=20=20=20=20=20(should=20(>=20= (buffer-size=20buf)=200))=0A+=20=20=20=20=20=20=20=20=20=20)=0A+=20=20=20= =20=20=20(when=20buf=0A+=20=20=20=20=20=20=20=20(kill-buffer=20buf)))))=0A= +=0A=20(provide=20'process-tests)=0A=20;;;=20process-tests.el=20ends=20= here=0A--=20=0A2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_93DD7399-6D1B-4332-9BC7-9937FCCD9906--