aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjuhlig <[email protected]>2019-05-13 10:15:16 +0200
committerLoïc Hoguin <[email protected]>2019-05-13 10:32:33 +0200
commita4af58b2e6313e3b422cf35aef370241aab20661 (patch)
tree6c50eaf301c93e30aa147651d9d8d9641845b23d
parent6d8b249e54c849948f6d4cdb021cb44340ec289f (diff)
downloadranch-a4af58b2e6313e3b422cf35aef370241aab20661.tar.gz
ranch-a4af58b2e6313e3b422cf35aef370241aab20661.tar.bz2
ranch-a4af58b2e6313e3b422cf35aef370241aab20661.zip
Fix premature ranch_server:set_addr
With num_listen_sockets>1 and SO_REUSEPORT disabled, the startup of ranch_acceptors_sup fails because extra sockets cannot be created. Because ranch_server:set_addr is called right after the creation of the first socket succeeded, ranch:get_port etc may still return an ok tuple until it notices that the listener is in fact down.
-rw-r--r--src/ranch_acceptors_sup.erl2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/ranch_acceptors_sup.erl b/src/ranch_acceptors_sup.erl
index 965862a..cba563e 100644
--- a/src/ranch_acceptors_sup.erl
+++ b/src/ranch_acceptors_sup.erl
@@ -51,7 +51,6 @@ init([Ref, NumAcceptors, Transport]) ->
start_listen_sockets(Ref, NumListenSockets, Transport, SocketOpts0, Logger) when NumListenSockets > 0 ->
BaseSocket = start_listen_socket(Ref, Transport, SocketOpts0, Logger),
{ok, Addr={_, Port}} = Transport:sockname(BaseSocket),
- ranch_server:set_addr(Ref, Addr),
SocketOpts = case lists:keyfind(port, 1, SocketOpts0) of
{port, Port} ->
SocketOpts0;
@@ -61,6 +60,7 @@ start_listen_sockets(Ref, NumListenSockets, Transport, SocketOpts0, Logger) when
ExtraSockets = [
{N, start_listen_socket(Ref, Transport, SocketOpts, Logger)}
|| N <- lists:seq(2, NumListenSockets)],
+ ranch_server:set_addr(Ref, Addr),
[{1, BaseSocket}|ExtraSockets].
-spec start_listen_socket(any(), module(), list(), module()) -> inet:socket().