From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Derek Zhou via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#40665: 28.0.50; tls hang on local ssl Date: Fri, 31 Jul 2020 23:22:02 +0000 (UTC) Message-ID: <86k0yjw9rb.fsf@mail.3qin.us> References: <86wo6fo78r.fsf@mail.3qin.us> <86eeslecnf.fsf@mail.3qin.us> <86blnnebh3.fsf@mail.3qin.us> <86zhb5hecx.fsf@mail.3qin.us> <86eeshpqdb.fsf@mail.3qin.us> <86zhb5q7sw.fsf@mail.3qin.us> <86y2qorj76.fsf@mail.3qin.us> <86368w1tge.fsf@mail.3qin.us> <864ktcfpm5.fsf@mail.3qin.us> <86368wfp6d.fsf@mail.3qin.us> <86y2qniu5m.fsf@mail.3qin.us> <86wo67im9w.fsf@mail.3qin.us> <86y2qnaqnv.fsf@mail.3qin.us> Reply-To: Derek Zhou Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22066"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.2.0; emacs 27.0.91 Cc: Glenn Morris , 40665@debbugs.gnu.org, Paul Eggert , Eli Zaretskii To: Robert Pluim Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 01 01:23:11 2020 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 1k1eMp-0005bB-DS for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 01 Aug 2020 01:23:11 +0200 Original-Received: from localhost ([::1]:40004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1eMn-0005Gi-RP for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 31 Jul 2020 19:23:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1eMg-0005GV-6c for bug-gnu-emacs@gnu.org; Fri, 31 Jul 2020 19:23:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55496) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k1eMf-0000fQ-TP for bug-gnu-emacs@gnu.org; Fri, 31 Jul 2020 19:23:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1k1eMf-0001eq-M5 for bug-gnu-emacs@gnu.org; Fri, 31 Jul 2020 19:23:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Derek Zhou Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 31 Jul 2020 23:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40665 X-GNU-PR-Package: emacs Original-Received: via spool by 40665-submit@debbugs.gnu.org id=B40665.15962377316302 (code B ref 40665); Fri, 31 Jul 2020 23:23:01 +0000 Original-Received: (at 40665) by debbugs.gnu.org; 31 Jul 2020 23:22:11 +0000 Original-Received: from localhost ([127.0.0.1]:38809 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k1eLq-0001da-Lc for submit@debbugs.gnu.org; Fri, 31 Jul 2020 19:22:10 -0400 Original-Received: from o50314941.outbound-mail.sendgrid.net ([50.31.49.41]:52791) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k1eLn-0001dL-VT for 40665@debbugs.gnu.org; Fri, 31 Jul 2020 19:22:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=3qin.us; h=references:from:subject:in-reply-to:mime-version:to:cc:content-type: content-transfer-encoding; s=s1; bh=nSswMbJNYIoqvt477Mg00/ME5s/pyddISVNcGjMl0nI=; b=QWZoLN/LwziR+G0McQJQKH4/d8FWR9DdgvGOxmrpWdTYRSGPbhHr10Lc8PbNQkERATk/ MFSzZ+QNb1mXfvwb/xEXzoild5nLV0dQrKaP6Z9Zwn61YyOKVsR4i8Bu5ti1dFvObSZdp+ eV7U2oDyHgw20V5wDW8n8gsoIvNHg1wHc= Original-Received: by filterdrecv-p3iad2-d8cc6d457-bt7pn with SMTP id filterdrecv-p3iad2-d8cc6d457-bt7pn-18-5F24A79A-33 2020-07-31 23:22:02.395408515 +0000 UTC m=+191620.141404834 Original-Received: from mail.3qin.us (unknown) by ismtpd0014p1las1.sendgrid.net (SG) with ESMTP id YVBAGGj4SvChvm88SnO6OQ Fri, 31 Jul 2020 23:22:02.049 +0000 (UTC) Original-Received: from derek by mail.3qin.us with local (Exim 4.92) (envelope-from ) id 1k1eLg-0000Fi-Ri; Fri, 31 Jul 2020 19:22:00 -0400 In-reply-to: <86y2qnaqnv.fsf@mail.3qin.us> X-SG-EID: nTv1epxWypfl0GRwygk8G5JZcpWJeBCcUM8ly3qzpbbVyfDgYog/9eXX7sL09UAmc1NAHbSe0kQLuY4uA55qD+qfYjrQM7JKJslwHeHOkGu0W4epJGcO7MAoRlSk1+mJu+Ef48dubOr8yhVfgxD08O4QoTkk3qokVk0IJkNvB63sDmiCb9z6OVYoj85vUivOsrWnEtYQLcRlDdX5ntHA+Kg/tVHrRmE8yXxlfeb5uZUj8nOUtzr2XpVbHOD217u6 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:183750 Archived-At: Robert, My patch still apply cleanly to either emacs-27 or master branch. I don't k= now who else can review this, so I am adding a few random people from the git log, sorry for the spam. Just don't it to sit in the dust and got forgotten= .=20 Derek Derek Zhou writes: > Robert Pluim writes: > >> OK, that does make sense, and might even be more correct, but it=CA=BCs = a >> bigger change. You'll need more than just me to agree with it. >> > Patch reworked: > > * before the select, check every interesting gnutls stream for > available data in the buffer > * if some of them hit, and either there is no wait_proc or the > wait_proc is one of the gnutls streams with new data, set the select > timeout to 0 > * after the select, merge the gnutls buffer status into the select > returns > > The patch is not much longer than before, still a net reduction of code > lines. I've done some light testing and haven't found any problem.=20 > > diff --git a/src/process.c b/src/process.c > index 91d426103d..783ce098b3 100644 > --- a/src/process.c > +++ b/src/process.c > @@ -5497,6 +5497,10 @@ wait_reading_process_output (intmax_t time_limit, = int nsecs, int read_kbd, > } > else > { > +#ifdef HAVE_GNUTLS > + int tls_nfds; > + fd_set tls_available; > +#endif > /* Set the timeout for adaptive read buffering if any > process has non-zero read_output_skip and non-zero > read_output_delay, and we are not reading output for a > @@ -5566,6 +5570,36 @@ wait_reading_process_output (intmax_t time_limit, = int nsecs, int read_kbd, > } > #endif > =20 > +#ifdef HAVE_GNUTLS > + /* GnuTLS buffers data internally. We need to check if some > + data is available in the buffers manually before the select. > + And if so, we need to skip the select which could block */ > + FD_ZERO (&tls_available); > + tls_nfds =3D 0; > + for (channel =3D 0; channel < FD_SETSIZE; ++channel) > + if (! NILP (chan_process[channel]) && FD_ISSET(channel, &Available)= ) > + { > + struct Lisp_Process *p =3D > + XPROCESS (chan_process[channel]); > + if (p && p->gnutls_p && p->gnutls_state > + && ((emacs_gnutls_record_check_pending > + (p->gnutls_state)) > + > 0)) > + { > + tls_nfds++; > + eassert (p->infd =3D=3D channel); > + FD_SET (p->infd, &tls_available); > + } > + } > + /* if wait_proc is somebody else, we have to wait in select as usual. > + Otherwisr, clobber the timeout */ > + if ((tls_nfds > 0) && > + (!wait_proc || > + (wait_proc->infd >=3D 0 && > + FD_ISSET(wait_proc->infd, &tls_available)))) > + timeout =3D make_timespec (0, 0); > +#endif > + > /* Non-macOS HAVE_GLIB builds call thread_select in xgselect.c. */ > #if defined HAVE_GLIB && !defined HAVE_NS > nfds =3D xg_select (max_desc + 1, > @@ -5584,60 +5618,22 @@ wait_reading_process_output (intmax_t time_limit,= int nsecs, int read_kbd, > #endif /* !HAVE_GLIB */ > =20 > #ifdef HAVE_GNUTLS > - /* GnuTLS buffers data internally. In lowat mode it leaves > - some data in the TCP buffers so that select works, but > - with custom pull/push functions we need to check if some > - data is available in the buffers manually. */ > - if (nfds =3D=3D 0) > + /* merge tls_available into Available */ > + if (tls_nfds > 0) > + { > + if (nfds =3D=3D 0 || (nfds < 0 && errno =3D=3D EINTR)) > { > - fd_set tls_available; > - int set =3D 0; > - > - FD_ZERO (&tls_available); > - if (! wait_proc) > - { > - /* We're not waiting on a specific process, so loop > - through all the channels and check for data. > - This is a workaround needed for some versions of > - the gnutls library -- 2.12.14 has been confirmed > - to need it. */ > - for (channel =3D 0; channel < FD_SETSIZE; ++channel) > - if (! NILP (chan_process[channel])) > - { > - struct Lisp_Process *p =3D > - XPROCESS (chan_process[channel]); > - if (p && p->gnutls_p && p->gnutls_state > - && ((emacs_gnutls_record_check_pending > - (p->gnutls_state)) > - > 0)) > - { > - nfds++; > - eassert (p->infd =3D=3D channel); > - FD_SET (p->infd, &tls_available); > - set++; > - } > - } > - } > - else > - { > - /* Check this specific channel. */ > - if (wait_proc->gnutls_p /* Check for valid process. */ > - && wait_proc->gnutls_state > - /* Do we have pending data? */ > - && ((emacs_gnutls_record_check_pending > - (wait_proc->gnutls_state)) > - > 0)) > - { > - nfds =3D 1; > - eassert (0 <=3D wait_proc->infd); > - /* Set to Available. */ > - FD_SET (wait_proc->infd, &tls_available); > - set++; > - } > - } > - if (set) > - Available =3D tls_available; > + /* fast path, just copy */ > + nfds =3D tls_nfds; > + Available =3D tls_available; > } > + else if (nfds > 0) > + /* slow path, merge one by one. > + Note: nfds does not need to be accurate, just positive is enough= */ > + for (channel =3D 0; channel < FD_SETSIZE; ++channel) > + if (FD_ISSET(channel, &tls_available)) > + FD_SET(channel, &Available); > + } > #endif > } > =20