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:20:03 +0000 (UTC) Message-ID: <864ktcfpm5.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> 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="41172"; 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:21:16 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 1jR1GW-000AZi-JX for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 Apr 2020 00:21:16 +0200 Original-Received: from localhost ([::1]:36884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR1GV-0005O7-F9 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 21 Apr 2020 18:21:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36994) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR1GK-0005O0-Lh for bug-gnu-emacs@gnu.org; Tue, 21 Apr 2020 18:21:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jR1GI-0006hm-MJ for bug-gnu-emacs@gnu.org; Tue, 21 Apr 2020 18:21:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39339) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jR1GH-0006gR-UR for bug-gnu-emacs@gnu.org; Tue, 21 Apr 2020 18:21:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jR1GH-0006kH-Q0 for bug-gnu-emacs@gnu.org; Tue, 21 Apr 2020 18:21: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: Tue, 21 Apr 2020 22:21: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.158750761125842 (code B ref 40665); Tue, 21 Apr 2020 22:21:01 +0000 Original-Received: (at 40665) by debbugs.gnu.org; 21 Apr 2020 22:20:11 +0000 Original-Received: from localhost ([127.0.0.1]:50885 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jR1FS-0006ik-Rs for submit@debbugs.gnu.org; Tue, 21 Apr 2020 18:20:11 -0400 Original-Received: from o50314941.outbound-mail.sendgrid.net ([50.31.49.41]:21741) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jR1FR-0006iR-2c for 40665@debbugs.gnu.org; Tue, 21 Apr 2020 18:20:10 -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=Xl+N1P8hd2xWf0gFwpqfD00uZRfTdJtb1CkgGx6EgPk=; b=o7tcbawtXhlCgaQqs7MotiJyxZ7BOnxNrvkvAETz2mY6vEbjCjZPFBtKwm9tsNNrmCLi MMEAy6yE5mNWoIFpIUFHanxvogrTcoqqgMCRopaOhrS7yw9DSIiEZUcz0lHwpaa9SUgO09 oDHCLindSu8PoqO0FSpflviCcukTE7t6A= Original-Received: by filterdrecv-p3iad2-8ddf98858-285bn with SMTP id filterdrecv-p3iad2-8ddf98858-285bn-19-5E9F7193-5B 2020-04-21 22:20:03.5482922 +0000 UTC m=+2322760.146725181 Original-Received: from mail.3qin.us (unknown) by ismtpd0003p1sjc2.sendgrid.net (SG) with ESMTP id TZGGQ2FUTo2Gi9Qr3yJGng Tue, 21 Apr 2020 22:20:03.232 +0000 (UTC) Original-Received: from derek by mail.3qin.us with local (Exim 4.92) (envelope-from ) id 1jR1FK-0007Fg-D6; Tue, 21 Apr 2020 18:20:02 -0400 In-reply-to: <86368w1tge.fsf@mail.3qin.us> X-SG-EID: nTv1epxWypfl0GRwygk8G5JZcpWJeBCcUM8ly3qzpbbVyfDgYog/9eXX7sL09UAmZ7BFZy6zOPCEh/asvQqjvmsrD8TVaTpTw4W7MuqqMPkhly1kobTDsFdGRFQAQV+PcBUkYIm6xXdXdgYXAzC6OIR2NoK6yOokAAM+zfjwsO1+zvyN7SbCL5Q9814y5IXzSFjCi+LyS3nc2tHIaLMPMdZjdPjefZqgTHQQoZX68HEM9WGt9qyjUPER3XA0fXrP 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:178767 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Derek Zhou writes: > Robert Pluim writes: > >> That=CA=BCs always possible. You'd have to stick some instrumentation in >> 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: --=-=-= 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..49b034b1a7 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])) + { + 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. */ --=-=-=--