Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Select cannot safely be used with programs that have more than 1024 file descriptors on a Linux system. This is because the underlying fd_set that the select system call uses is a fixed sized buffer i.e. its size is allocated at compile time, not run time.</p> <p>From man 2 select:</p> <pre><code>int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); </code></pre> <blockquote> <p>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.</p> </blockquote> <p>This means that if you have more than 1024 file descriptors in your program, and you use the select system call, you will end up with memory corruption.</p> <p>If you want to use more than 1024 file descriptors in your program, you <em>must</em> use poll or epoll, and ensure that you never use select, or you will get random memory corruption. Changing the size of the file descriptor table through <code>ulimit</code> is very dangerous if you are using <code>select</code>. Don't do it.</p> <p>Ruby's select does seem to be actually implemented with the select system call, so while it may look like increasing <code>ulimit</code> works, under the hood corruption is happening: <a href="https://github.com/ruby/ruby/blob/trunk/thread.c" rel="nofollow">https://github.com/ruby/ruby/blob/trunk/thread.c</a></p> <p>Furthermore, some unrelated API's in ruby seem to use select (see thread_pthread.c) so it's probably also unsafe to use those, or any code that uses those API's within a ruby program running with a file descriptor table larger than 1024.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload