Subject: bug#15075: 24.3.50; Infinite loop when closing some connections

From: Lars Magne Ingebrigtsen <[email-masked]>
Date: Mon, 12 Aug 2013 18:04:56 +0200

This is what's hanging.  If we get any other errors than EIO, EAGAIN or
EWOULDBLOCK, then we infloop here.  And we get EBADF, so this infloops.

	  /* Read data from the process, until we exhaust it.  */
	  while (wait_proc->infd >= 0)
	    {
	      int nread = read_process_output (proc, wait_proc->infd);

	      if (nread == 0)
		break;

	      if (nread > 0)
		got_some_input = read_some_bytes = 1;
	      else if (nread == -1 && (errno == EIO || errno == EAGAIN))
		break;
#ifdef EWOULDBLOCK
	      else if (nread == -1 && EWOULDBLOCK == errno)
		break;
#endif
	    }

I'm guessing that something is supposed to set wait_proc->infd something
smaller than zero somewhere if a serious error happens.

Yup:

(gdb) print wait_proc->open_fd
$12 = {-1, -1, -1, -1, -1, -1}
(gdb) print wait_proc->infd   
$13 = 21

And this looks like the likely culprit:

-      p->infd  = -1;
-      p->outfd = -1;
+  for (i = 0; i < PROCESS_OPEN_FDS; i++)
+    close_process_fd (&p->open_fd[i]);

So there's some disagreement about what's saying whether sockets are
open or not, and if the closing happens at the wrong time, we infloop.

-- 
(domestic pets only, the antidote for overdose, milk.)
  No Gnus T-Shirt for sale: http://ingebrigtsen.no/no.php
  and http://lars.ingebrigtsen.no/2013/08/twenty-years-of-september.html