-
Type: New Feature
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Internal Code
-
Server Programmability
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.
- is related to
-
SERVER-78384 mongos should allow --port 0
- Closed