public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* odd socketpair() failure
@ 2011-08-03 23:09 Eric Blake
  2011-08-04  6:00 ` Marco atzeri
  2011-08-04  8:26 ` Corinna Vinschen
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Blake @ 2011-08-03 23:09 UTC (permalink / raw)
  To: cygwin

A while ago, I tested pipe() for EMFILE failures [1].  Well, I repeated 
those tests for socketpair() [2], and cygwin is once again the odd man out.

[1] http://cygwin.com/ml/cygwin/2011-06/msg00328.html
[2] http://austingroupbugs.net/view.php?id=483

$ cat foo.c
#define _POSIX_C_SOURCE 200811L
#define __EXTENSIONS__ 1
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/socket.h>
int
main (int argc, char **argv)
{
   int last;
   int fd[2] = {-2,-3};
   int err;
   /* Get to an EMFILE condition.  */
   while (1) {
     int fd = open("/dev/null", O_RDONLY);
     if (fd < 0) {
       printf ("after fd %d, open failed with errno %d %s\n",
	      last, errno, strerror(errno));
       break;
     }
     last = fd;
   }
   /* Probe behavior */
   err = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
   if (err)
     printf ("try 1, socketpair returned %d errno %d %s, fds %d %d\n",
	    err, errno, strerror(errno), fd[0], fd[1]);
   else
     printf ("try 1, socketpair succeeded, fds %d %d\n", fd[0], fd[1]);
   if (close(last))
     return 1;
   err = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
   if (err)
     printf ("try 2, socketpair returned %d errno %d %s, fds %d %d\n",
	    err, errno, strerror(errno), fd[0], fd[1]);
   else
     printf ("try 2, socketpair succeeded, fds %d %d\n", fd[0], fd[1]);
   if (close(0))
     return 1;
   err = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
   if (err)
     printf ("try 3, socketpair returned %d errno %d %s, fds %d %d\n",
	    err, errno, strerror(errno), fd[0], fd[1]);
   else
     printf ("try 3, socketpair succeeded, fds %d %d\n", fd[0], fd[1]);
   return 0;
}
$ ./foo
after fd 3199, open failed with errno 24 Too many open files
try 1, socketpair returned -1 errno 24 Too many open files, fds -2 -3
try 2, socketpair returned -1 errno 24 Too many open files, fds -2 -3
try 3, socketpair returned -1 errno 24 Too many open files, fds -2 -3

But on Linux, try 3 succeeds.  Something in cygwin is not quite right on 
try 3 - the program explicitly freed two fd slots (0 and 3199), so it 
should have plenty of room to create the socketpair without hitting EMFILE.

Disclaimer: I tested on 1.7.9 rather than the latest snapshot; maybe the 
pipe() fix in the meantime also fixed socketpair()?

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: odd socketpair() failure
  2011-08-03 23:09 odd socketpair() failure Eric Blake
@ 2011-08-04  6:00 ` Marco atzeri
  2011-08-04  8:26 ` Corinna Vinschen
  1 sibling, 0 replies; 3+ messages in thread
From: Marco atzeri @ 2011-08-04  6:00 UTC (permalink / raw)
  To: cygwin

On 8/4/2011 1:09 AM, Eric Blake wrote:
> A while ago, I tested pipe() for EMFILE failures [1]. Well, I repeated
> those tests for socketpair() [2], and cygwin is once again the odd man out.
>
> [1] http://cygwin.com/ml/cygwin/2011-06/msg00328.html
> [2] http://austingroupbugs.net/view.php?id=483
>
> $ cat foo.c
> #define _POSIX_C_SOURCE 200811L
> #define __EXTENSIONS__ 1
> #include <sys/types.h>
> #include <sys/time.h>
> #include <unistd.h>
> #include <string.h>
> #include <stdio.h>
> #include <errno.h>
> #include <fcntl.h>
> #include <sys/socket.h>
> int
> main (int argc, char **argv)
> {
> int last;
> int fd[2] = {-2,-3};
> int err;
> /* Get to an EMFILE condition. */
> while (1) {
> int fd = open("/dev/null", O_RDONLY);
> if (fd < 0) {
> printf ("after fd %d, open failed with errno %d %s\n",
> last, errno, strerror(errno));
> break;
> }
> last = fd;
> }
> /* Probe behavior */
> err = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
> if (err)
> printf ("try 1, socketpair returned %d errno %d %s, fds %d %d\n",
> err, errno, strerror(errno), fd[0], fd[1]);
> else
> printf ("try 1, socketpair succeeded, fds %d %d\n", fd[0], fd[1]);
> if (close(last))
> return 1;
> err = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
> if (err)
> printf ("try 2, socketpair returned %d errno %d %s, fds %d %d\n",
> err, errno, strerror(errno), fd[0], fd[1]);
> else
> printf ("try 2, socketpair succeeded, fds %d %d\n", fd[0], fd[1]);
> if (close(0))
> return 1;
> err = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
> if (err)
> printf ("try 3, socketpair returned %d errno %d %s, fds %d %d\n",
> err, errno, strerror(errno), fd[0], fd[1]);
> else
> printf ("try 3, socketpair succeeded, fds %d %d\n", fd[0], fd[1]);
> return 0;
> }
> $ ./foo
> after fd 3199, open failed with errno 24 Too many open files
> try 1, socketpair returned -1 errno 24 Too many open files, fds -2 -3
> try 2, socketpair returned -1 errno 24 Too many open files, fds -2 -3
> try 3, socketpair returned -1 errno 24 Too many open files, fds -2 -3
>
> But on Linux, try 3 succeeds. Something in cygwin is not quite right on
> try 3 - the program explicitly freed two fd slots (0 and 3199), so it
> should have plenty of room to create the socketpair without hitting EMFILE.
>
> Disclaimer: I tested on 1.7.9 rather than the latest snapshot; maybe the
> pipe() fix in the meantime also fixed socketpair()?
>
same result on latest CVS

Marco

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: odd socketpair() failure
  2011-08-03 23:09 odd socketpair() failure Eric Blake
  2011-08-04  6:00 ` Marco atzeri
@ 2011-08-04  8:26 ` Corinna Vinschen
  1 sibling, 0 replies; 3+ messages in thread
From: Corinna Vinschen @ 2011-08-04  8:26 UTC (permalink / raw)
  To: cygwin

On Aug  3 17:09, Eric Blake wrote:
> A while ago, I tested pipe() for EMFILE failures [1].  Well, I
> repeated those tests for socketpair() [2], and cygwin is once again
> the odd man out.
> [...]
> after fd 3199, open failed with errno 24 Too many open files
> try 1, socketpair returned -1 errno 24 Too many open files, fds -2 -3
> try 2, socketpair returned -1 errno 24 Too many open files, fds -2 -3
> try 3, socketpair returned -1 errno 24 Too many open files, fds -2 -3
> 
> But on Linux, try 3 succeeds.  Something in cygwin is not quite
> right on try 3 - the program explicitly freed two fd slots (0 and
> 3199), so it should have plenty of room to create the socketpair
> without hitting EMFILE.

The socketpair function forgot to free the descriptor slot of the first
socket if there was no room left for the second socket.  Fixed in CVS.


Thanks,
Corinna


-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-08-04  8:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-03 23:09 odd socketpair() failure Eric Blake
2011-08-04  6:00 ` Marco atzeri
2011-08-04  8:26 ` Corinna Vinschen

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).