unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@gmail.com>
To: 6074@debbugs.gnu.org
Subject: bug#6074: accept-process-output on listening sockets cause non-interruptible infloop
Date: Mon, 22 Jul 2019 03:52:33 +0000	[thread overview]
Message-ID: <CAOqdjBfKkdExF1366V_W-UhDXrB27EQyJ1-PF1HeiFmErY=LrQ@mail.gmail.com> (raw)
In-Reply-To: <m2y6g3mfom.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 946 bytes --]

> With this code Emacs seems to be stuck in an endless loop and is not
> incorruptible with C-g:

> (let ((proc (make-network-process :name "foo" :server t :noquery t
>  :family 'local :service "/tmp/foo.socket")))
>   (accept-process-output proc))

On Linux, the problem appears to be that we don't abort this infloop
in process.c if a read () returns EINVAL:

          while (true)
        {
          int nread = read_process_output (proc, wait_proc->infd);
          if (nread < 0)
            {
              if (errno == EIO || would_block (errno))
            break;
            }
          else
            {
              if (got_some_output < nread)
            got_some_output = nread;
              if (nread == 0)
            break;
              read_some_bytes = true;
            }
        }

That seems problematic to me, since we might get non-EIO errors for
other reasons. I'm attaching a patch that appears to fix the issue.

[-- Attachment #2: 0001-Don-t-retry-reading-after-receiving-EINVAL-bug-6074.patch --]
[-- Type: text/x-patch, Size: 849 bytes --]

From ad294bb1e7ff7012dca3345a8ca2046e0f9dc8fb Mon Sep 17 00:00:00 2001
From: Pip Cet <pipcet@gmail.com>
Date: Mon, 22 Jul 2019 03:49:54 +0000
Subject: [PATCH] Don't retry reading after receiving EINVAL (bug#6074)

* src/process.c (wait_reading_process_output): Don't retry reading
from an fd after an unknown error.
---
 src/process.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/process.c b/src/process.c
index abadabe77e..1311409274 100644
--- a/src/process.c
+++ b/src/process.c
@@ -5277,7 +5277,9 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
 		  int nread = read_process_output (proc, wait_proc->infd);
 		  if (nread < 0)
 		    {
-		      if (errno == EIO || would_block (errno))
+		      if (errno == EINTR)
+			continue;
+		      else
 			break;
 		    }
 		  else
-- 
2.22.0


  reply	other threads:[~2019-07-22  3:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-01 22:15 bug#6074: 24.0.50; accept-process-output on listening sockets not incorruptible Helmut Eller
2019-07-22  3:52 ` Pip Cet [this message]
2019-07-22 14:26   ` bug#6074: accept-process-output on listening sockets cause non-interruptible infloop Eli Zaretskii
2019-07-22 17:45     ` Pip Cet
2020-09-14 13:21       ` Lars Ingebrigtsen
2019-07-23  2:46   ` Richard Stallman
2019-07-23 14:31     ` Pip Cet
2019-07-25  3:08       ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOqdjBfKkdExF1366V_W-UhDXrB27EQyJ1-PF1HeiFmErY=LrQ@mail.gmail.com' \
    --to=pipcet@gmail.com \
    --cc=6074@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).