]> granicus.if.org Git - ejabberd/commit
Bind listener ports early and start accepting connections later
authorAndreas Köhler <andreas.koehler@1und1.de>
Tue, 2 Nov 2010 13:43:03 +0000 (14:43 +0100)
committerBadlop <badlop@process-one.net>
Wed, 10 Nov 2010 22:46:16 +0000 (23:46 +0100)
commit1f1d2bd5f52ce6376ad2d9f577da5323b1582a9c
treeacb7a444108a6c13a9cb9a80361a892c814ac9b3
parent0c484369c9d8b01d5407450d8741f8ca52ccc442
Bind listener ports early and start accepting connections later

It may happen that auth or rdbms client tcp connections bind a local
socket to a port number required by a configered listener. The ejabberd
applications fails to start up and needs to be restarted.

In plain C you would bind(2) the listener port and listen(2) later on.
gen_tcp:listen/2 does not allow to separate these two steps though, so
another way is not to accept connections while start up. OTOH, the
kernel will syn/ack incoming connections and receive data, leaving them
in a buffer for the ejabberd to read from. If this is unwanted, a load
balancer would need to receive data from the ejabberd server before
adding the node to its pool.

This patch binds tcp ports while initializing the ejabberd_listener
process, storing ListenSockets in an ets table. start_listeners/0 will
reuse these ports later on.
src/ejabberd_listener.erl