socket file descriptor (1063) is larger than FD_SETSIZE (1024), you probably need to rebuild Apache with a larger FD_SETSIZE

15,152

This is because mod_fastcgi uses select() as a multiplexing option. Select is pretty bad for this stuff, the man page specifies for select;

An fd_set is a fixed size buffer. Executing FD_CLR() or FD_SET() with a value of fd that is negative or is equal to or larger than FD_SETSIZE will result in undefined behavior. Moreover, POSIX requires fd to be a valid file descriptor.

FD_SETSIZE is normally 1024, so file descriptors over 1024 are not supported in general. You can fiddle with the FD_SETSIZE include sizes as you have done but making changes like this might impact other programs too which aim to be POSIX compliant. In my opinion, if the application writer is suggesting altering system source code to make this work then the application is fundamentally broken.

I suggest moving off of mod_fastcgi and using another implementation. Depending on how your staring your FastCGI daemons can depend on how you do this.

mod_fcgid is one option or newer apaches can use mod_proxy_fcgi instead.

Share:
15,152

Related videos on Youtube

Spacedust
Author by

Spacedust

Updated on September 18, 2022

Comments

  • Spacedust
    Spacedust over 1 year

    My Apache is throwing Internal Server Error 500 errors and logs like this:

    > [Sun Apr 07 23:35:24 2013] [error] [client 124.162.30.45] (2)No such
    > file or directory: FastCGI: failed to connect to server
    > "/home/magda_00aa/sportxxx.pl/sportxxx.pl.0fake": socket file
    > descriptor (1063) is larger than FD_SETSIZE (1024), you probably need
    > to rebuild Apache with a larger FD_SETSIZE, referer:
    > http://www.surf4web.com/surfing.php?id=haoduodeng2012
    

    I've upped FD limits inside:

    cat /usr/include/bits/typesizes.h | grep FD
    #define __FD_SETSIZE            65536
    

    and

    cat /usr/include/linux/posix_types.h | grep FD_SETSIZE
    #undef __FD_SETSIZE
    #define __FD_SETSIZE    65536
    #define __FDSET_LONGS   (__FD_SETSIZE/__NFDBITS)
    

    and also

    /sbin/sysctl fs.file-max
    fs.file-max = 512000
    
    ulimit -n
    1000000
    

    but it didn't helped. My Apache is still crashing if more than 350 virtualhosts :/

    I'm on CentOS 5.9 64-bit - kernel 3.0.65-1.el5.elrepo

    • Rahly
      Rahly over 10 years
      Please note that the "fd_set" is a kernel structure, changing FD_SETSIZE would require recompiling the kernel itself. Otherwise, the kernel is still going to use a max of whatever the original is. Also the normal default is set to 1024 which uses 128 bytes of memory, 65536 requires 8k of memory per structure.
  • Spacedust
    Spacedust about 11 years
    I'm using php-fpm
  • Matthew Ife
    Matthew Ife about 11 years
    FastCGI is merely a protocol, whatever you are using for the server side is not the issue, the client side is what is causing your issues.
  • Spacedust
    Spacedust about 11 years
    How to recompile Apache properly ? I can't find any setting inside it's config files.
  • Spacedust
    Spacedust about 11 years
    Recompiled apache and all working fine :D