Skip to content

add note about Unix.select and "Invalid argument" errors #222

Closed

Description

@edwintorok

Please update the manual to mention that if you see an Invalid argument' onUnix.select' it means that this 1024 file descriptor limit was exceeded:
"libev is used by default on Unix, because it supports any number of file descriptors while Unix.select supports only 1024 at most, and is also much more efficient. "

Background:

Just hit the problem described here with Ocsigenserver: http://blog.mashape.com/scaling-up-api-proxy-ocaml/:
Mar 11 16:18:04: main: Fatal - select(): Invalid argument

(and sometimes it would fail with Unix_error 12, which would be ENOMEM).

The problem was that lwt wasn't built with libev, and it falled back to Unix.select.
If you google for EINVAL on select you usually see that the timeout argument might be wrong, but that was not my case.
OCaml's Unix.select also fails with EINVAL if the maximum file descriptor number exceeds FD_SET_SIZE (1024 on Linux), which I found out by looking at its source code.

I was running my app inside a Docker container, where the default ulimit -n is 1048576, so although ocsigen would only accept 350 connections by default, some file descriptor numbers would exceed 1024 (even if it didn't actually try to poll more than 1024 at a time), and cause this error.

Switching to libev solved all these problems.

Activity

  1. hannesm commented on Apr 8, 2016

    @hannesm
    Contributor

    thanks @edwintorok for writing this up! I just encountered the very same issue...

  2. aantron commented on Apr 29, 2016

    @aantron
    Collaborator

    Where in the manual would it have been the most useful, as in with the greatest chance of you seeing it? PRs are also welcome :)

  3. added a commit that references this issue on Jun 29, 2018
  4. added a commit that references this issue on Oct 16, 2025
    7f92aa2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions