From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Derek Zhou Newsgroups: gmane.emacs.bugs Subject: bug#40665: 28.0.50; tls hang on local ssl Date: Tue, 21 Apr 2020 22:29:30 +0000 (UTC) Message-ID: <86368wfp6d.fsf@mail.3qin.us> References: <86wo6fo78r.fsf@mail.3qin.us> <86imhz5m0f.fsf@mail.3qin.us> <86h7xj5fae.fsf@mail.3qin.us> <86ftd35930.fsf@mail.3qin.us> <86d086dkgq.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> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="79462"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.2.0; emacs 27.0.91 Cc: 40665@debbugs.gnu.org To: Robert Pluim Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 22 00:30:29 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 1jR1PQ-000Kav-T7 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 Apr 2020 00:30:28 +0200 Original-Received: from localhost ([::1]:37026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR1PP-00085M-Tr for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 21 Apr 2020 18:30:27 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48160) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR1P6-000858-Iy for bug-gnu-emacs@gnu.org; Tue, 21 Apr 2020 18:30:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jR1P3-0000Ev-4b for bug-gnu-emacs@gnu.org; Tue, 21 Apr 2020 18:30:06 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39358) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jR1P0-0000CO-Uv for bug-gnu-emacs@gnu.org; Tue, 21 Apr 2020 18:30:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jR1P0-0006yE-Ot for bug-gnu-emacs@gnu.org; Tue, 21 Apr 2020 18:30:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Derek Zhou Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 21 Apr 2020 22:30:02 +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.158750817926743 (code B ref 40665); Tue, 21 Apr 2020 22:30:02 +0000 Original-Received: (at 40665) by debbugs.gnu.org; 21 Apr 2020 22:29:39 +0000 Original-Received: from localhost ([127.0.0.1]:50904 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jR1Oc-0006xG-TO for submit@debbugs.gnu.org; Tue, 21 Apr 2020 18:29:39 -0400 Original-Received: from xtrwkkxd.outbound-mail.sendgrid.net ([167.89.17.173]:39079) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jR1Oa-0006x1-OW for 40665@debbugs.gnu.org; Tue, 21 Apr 2020 18:29:37 -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; s=s1; bh=NBgo14djU+xbyqz28zVHqrShZHO2OdXZY9XXczChZEw=; b=P8Z0Kj95H/QG38n14Sb/Nzxvf5ROwm+mz8nziO1d9n0blL5gL/gQ4L7IJ2FKjoVDl3Wx pVs0TXH7BOjTSDX435edSxiRn8NOpY4mUEtyLHR7X030jBGhZpXIAIOZA605XEu5w/eZqO OmpSXp1fHaY0KGiggYyzbfGLjnQ9IyuI0= Original-Received: by filter0072p3las1.sendgrid.net with SMTP id filter0072p3las1-6642-5E9F73CA-FE 2020-04-21 22:29:30.879111203 +0000 UTC m=+520055.018223618 Original-Received: from mail.3qin.us (unknown) by ismtpd0013p1las1.sendgrid.net (SG) with ESMTP id EOxmKH4XTnK3mCCv0GDLiA Tue, 21 Apr 2020 22:29:30.687 +0000 (UTC) Original-Received: from derek by mail.3qin.us with local (Exim 4.92) (envelope-from ) id 1jR1OU-0007Jy-6h; Tue, 21 Apr 2020 18:29:30 -0400 In-reply-to: <864ktcfpm5.fsf@mail.3qin.us> X-SG-EID: nTv1epxWypfl0GRwygk8G5JZcpWJeBCcUM8ly3qzpbbVyfDgYog/9eXX7sL09UAmF8iln4V4Yw/cI7KRgFe7RkZP9gwF/Iq9UCax74AOehJQOR/LFNj37gImnZYCxnju92TPoE0R4xMQWV1eiVYuKuqxI+e5TfqVfWkUaiLXupa1I4C0XBUtWVxi0sjkLB0wMmUbqVqi2ErMEmx84Kc0/tELZxHVvr/0U2HVtcUapGk= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Received-From: 209.51.188.43 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:178768 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Derek Zhou writes: > Derek Zhou writes: > >> Robert Pluim writes: >> >>> That=CA=BCs always possible. You'd have to stick some instrumentation i= n >>> things like connect_network_socket and wait_reading_process_output to >>> narrow it down. >>> >> I think what happened is gnutls's internal buffering exhausts the >> available data from the socket, so select blocks. There is an comment in >> the code said gnutls leave one byte in the socket for select, but I >> don't think it is doing this anymore. The following patch move the check >> before the select and skip the select if there is data to be read in >> gnutls. It fixed the occational stall in https. > > Sorry, the previous patch was wrong. Cannot reuse the fd_set intended > for select. Corrected: > Version 3, add safty guard for tls read detection. Please use this one. You may want to review this carefully. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=check_pending_before_select.patch diff --git a/src/process.c b/src/process.c index 91d426103d..683c28b3fd 100644 --- a/src/process.c +++ b/src/process.c @@ -5566,7 +5566,38 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, } #endif -/* Non-macOS HAVE_GLIB builds call thread_select in xgselect.c. */ +#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_set tls_available; + FD_ZERO (&tls_available); + nfds = 0; + for (channel = 0; channel < FD_SETSIZE; ++channel) + if (! NILP (chan_process[channel]) && FD_ISSET(channel, &Available)) + { + struct Lisp_Process *p = + 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 == channel); + FD_SET (p->infd, &tls_available); + } + } + /* don't select if we have something here */ + if (nfds > 0) { + Available = tls_available; + goto SELECT_END; + } + } +#endif + + /* Non-macOS HAVE_GLIB builds call thread_select in xgselect.c. */ #if defined HAVE_GLIB && !defined HAVE_NS nfds = xg_select (max_desc + 1, &Available, (check_write ? &Writeok : 0), @@ -5582,65 +5613,9 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, (check_write ? &Writeok : 0), NULL, &timeout, NULL); #endif /* !HAVE_GLIB */ - -#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 == 0) - { - fd_set tls_available; - int set = 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 = 0; channel < FD_SETSIZE; ++channel) - if (! NILP (chan_process[channel])) - { - struct Lisp_Process *p = - 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 == 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 = 1; - eassert (0 <= wait_proc->infd); - /* Set to Available. */ - FD_SET (wait_proc->infd, &tls_available); - set++; - } - } - if (set) - Available = tls_available; - } -#endif } + SELECT_END: xerrno = errno; /* Make C-g and alarm signals set flags again. */ --=-=-=--