From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.devel Subject: Re: wait_reading_process_ouput hangs in certain cases (w/ patches) Date: Tue, 13 Mar 2018 14:40:54 +0100 Message-ID: <87zi3cdrfd.fsf@gmail.com> References: <709614e8-1937-07c1-f554-b453ed4f3d4a@binary-island.eu> <7550438b-9fd4-d374-e571-8bb16456cad5@cs.ucla.edu> <797d0e16-1bae-50c2-35f8-05489ffce935@binary-island.eu> <83tvugdiu5.fsf@gnu.org> <877er5s0xv.fsf@gmail.com> <4e4c72bb-295d-81e1-e4ed-cad256bca83c@binary-island.eu> <87zi3v9461.fsf@gmail.com> <87k1uy8x68.fsf@gmail.com> <6d1970af-8c5c-20ba-be09-0b9aa757d663@binary-island.eu> <13b3e003-d12b-33a7-3ebe-c07b017a7cc0@binary-island.eu> <87r2oow3uc.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1520948410 1187 195.159.176.226 (13 Mar 2018 13:40:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 13 Mar 2018 13:40:10 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 13 14:40:06 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1evk9r-0000Ac-VD for ged-emacs-devel@m.gmane.org; Tue, 13 Mar 2018 14:40:04 +0100 Original-Received: from localhost ([::1]:40052 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evkBu-0005rK-PK for ged-emacs-devel@m.gmane.org; Tue, 13 Mar 2018 09:42:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evkAz-0005Gd-Sc for emacs-devel@gnu.org; Tue, 13 Mar 2018 09:41:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evkAv-0006Gn-UF for emacs-devel@gnu.org; Tue, 13 Mar 2018 09:41:13 -0400 Original-Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:35289) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1evkAv-0006Fk-IH for emacs-devel@gnu.org; Tue, 13 Mar 2018 09:41:09 -0400 Original-Received: by mail-wr0-x244.google.com with SMTP id n12so11691119wra.2 for ; Tue, 13 Mar 2018 06:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:references:mail-followup-to:mail-copies-to :gmane-reply-to-list:date:message-id:mime-version; bh=FWGj2HI0tKULZ3VVOLbTYTnVL2rDP/JZOUs+0uIuvVk=; b=psGrjcDt5o0yFfDHWUlU6FJ8nkHC6UlR35fanmt1qp8Ec2ciDHVbrJGzcMM9bxPpIN gR0dUDyvezgg2OJ1rfVCAyirTMHzLvuk8UY5O8emf7I2lMR2fTJWWK7YItE0Qwp//I/y mxHw5IcVVTJdx0oJtNxYQDqsmbVxP/V6KEJg26iisrEjnw3Ccgfu81fyRz+U7U839W1f JpUlIHXlQ3uRNOgb96pEut80e7uOWUq8pPGdtI7OB2OZJzjF+571Sx+cBq2CDCJRon2a rAk4IYAY+kBiyKJz5VqTNt6i3GOiKlneQRIRTwUT9n/eKk9qlymbS+93cRVAEQm+l0Au LKvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:mail-followup-to :mail-copies-to:gmane-reply-to-list:date:message-id:mime-version; bh=FWGj2HI0tKULZ3VVOLbTYTnVL2rDP/JZOUs+0uIuvVk=; b=qjWzOvtIoI8Q9v55/CpHfry9oZAfjRWicKRNopkA46AoHT98D/Be85vfuQbgGcryU6 VupmC6RBav6+llpTdE+r7u3Ov3QYD7WqHrNLpfbF8ejpPM4VL9AljSah/IA1t5IRUInv ZqCuQlw2b4lYeoYwrd5u7KCTC5On3KIFHjB6wxo9M9Yjvc5P5uMoPJx3wbJQ9fp8zoAr Cc5JsJWPan3UCxCwqtiAgcegJZ5aHU/IzmL4EvLQE8Jb1LmOG950fQd8VjSv3beBI6xr bL+RXFRY2JTlXzF7XY+c6BsTA6uRMEOizwdiUHpmCk3+4oRWo+zNETk/ZfDfNOmmQlHT 6J0A== X-Gm-Message-State: AElRT7HGaw1cAWgREgyuQdi77x1ca77rcKTl+keZPnlkj2JsIDqipXBw Iose0Jkld8QchDBgIdMclI1NAzYvFbo= X-Google-Smtp-Source: AG47ELtXIkwyLWhEN3bX2ymI+/YrAsG0kaUVs6PuVYydk5038yknZoQMziTCJHP+/Iksgn6KArzVWw== X-Received: by 10.223.154.182 with SMTP id a51mr672387wrc.176.1520948467982; Tue, 13 Mar 2018 06:41:07 -0700 (PDT) Original-Received: from rpluim-ubuntu ([149.5.228.1]) by smtp.gmail.com with ESMTPSA id 140sm341027wmi.34.2018.03.13.06.41.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Mar 2018 06:41:07 -0700 (PDT) Mail-Followup-To: emacs-devel@gnu.org Mail-Copies-To: never Gmane-Reply-To-List: yes X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::244 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:223687 Archived-At: --=-=-= Content-Type: text/plain Robert Pluim writes: > Matthias Dahl writes: > >> - if (set) >> - Available = tls_available; >> + for (channel = 0; channel < FD_SETSIZE; ++channel) >> + if (! NILP (chan_process[channel])) >> + { >> + struct Lisp_Process *p = >> + XPROCESS (chan_process[channel]); >> + >> + if (just_wait_proc && p != wait_proc) >> + continue; >> + >> + 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, &Available); >> + } >> + } >> } >> #endif >> } > > Hi Matthias, I apologize if this has already been mentioned, but did > you check that this doesn't undo the fix for Bug#21337? The issue > there as I recall was that FD's were set in Available that didn't > actually have data to read, hence the need to check the TLS FD's > separately using tls_available. Answering my own question: your second patch undoes the fix for 21337. I think it needs to look something like this (I've put some of the tabs back in to make the diff clearer, adjust according to taste): --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/src/process.c b/src/process.c index 11d914aab2..71b638726f 100644 --- a/src/process.c +++ b/src/process.c @@ -5392,58 +5392,36 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, #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) + /* GnuTLS buffers data internally. select() will only report + available data for the underlying kernel sockets API, not + what has been buffered internally. As such, we need to loop + through all channels and check for available data 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. See - http://comments.gmane.org/gmane.emacs.devel/145074 */ - 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++; - } - } + for (channel = 0; channel < FD_SETSIZE; ++channel) + if (! NILP (chan_process[channel])) + { + struct Lisp_Process *p = + XPROCESS (chan_process[channel]); + + if (just_wait_proc && p != wait_proc) + continue; + + 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++; + } + } if (set) Available = tls_available; } --=-=-=--