Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-78520

Make mongo servers use a file handle to accept new connections

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Internal Code
    • Labels:
      None
    • Service Arch

      For testing purposes it's useful to start mongod with `--port=0` to have the server choose an arbitrary free port. This approach is still messy, though, because the way to recover that port (in a cross-platform way) is to parse it out of the log.

      It also, as of this writing, doesn't work with mongos. (cf. SERVER-78384)

      One alternative is, in the calling process, to bind() a new socket to port 0, not its port, then close the socket and assign that port to mongod. This, though, isn't race-safe.

      A more ideal solution would be to allow mongod/mongos to accept a raw file descriptor in lieu of a port. That file descriptor would need to be of the appropriate type and be pre-bind()ed, and the calling process would need to a) disable the socket's cloexec flag, and b) close the socket after the fork. That way, the calling process can know in advance which freely-chosen port number mongod will use.

      This could also be useful with, e.g., systemd or xinetd, which I believe use this functionality to allow daemons to go "dormant".

      Caveat: I don't know how applicable this pattern would be outside POSIX OSes.

      Note: filing this on behalf of felipe.gasper@mongodb.com.

            Assignee:
            backlog-server-servicearch [DO NOT USE] Backlog - Service Architecture
            Reporter:
            amirsaman.memaripour@mongodb.com Amirsaman Memaripour
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: