aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2018-03-12 14:23:33 +0100
committerHans Nilsson <[email protected]>2018-03-12 14:23:33 +0100
commita4d14013823bd35b46b7c8ca7845e3df22527d80 (patch)
treed657261a58a61d2d3ff3c5f2081278b5c0913f81
parent56c692e48d37bfd46e55939c0c73833e5cb85131 (diff)
parent7a86736c1e2bc0468acd18b1f84c7cbf055befc8 (diff)
downloadotp-a4d14013823bd35b46b7c8ca7845e3df22527d80.tar.gz
otp-a4d14013823bd35b46b7c8ca7845e3df22527d80.tar.bz2
otp-a4d14013823bd35b46b7c8ca7845e3df22527d80.zip
Merge branch 'hans/ssh/acceptor_restart/OTP-14955'
* hans/ssh/acceptor_restart/OTP-14955: ssh: Retry and exponentially backoff listener restart
-rw-r--r--lib/ssh/src/ssh_acceptor.erl16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/ssh/src/ssh_acceptor.erl b/lib/ssh/src/ssh_acceptor.erl
index d66a34c58a..27d4242dd4 100644
--- a/lib/ssh/src/ssh_acceptor.erl
+++ b/lib/ssh/src/ssh_acceptor.erl
@@ -86,7 +86,8 @@ acceptor_init(Parent, Port, Address, Opts, AcceptTimeout) ->
acceptor_loop(Callback, Port, Address, Opts, LSock, AcceptTimeout);
{error,_} -> % Not open, a restart
- {ok,NewLSock} = listen(Port, Opts),
+ %% Allow gen_tcp:listen to fail 4 times if eaddrinuse:
+ {ok,NewLSock} = try_listen(Port, Opts, 4),
proc_lib:init_ack(Parent, {ok, self()}),
Opts1 = ?DELETE_INTERNAL_OPT(lsocket, Opts),
{_, Callback, _} = ?GET_OPT(transport, Opts1),
@@ -98,6 +99,19 @@ acceptor_init(Parent, Port, Address, Opts, AcceptTimeout) ->
end.
+try_listen(Port, Opts, NtriesLeft) ->
+ try_listen(Port, Opts, 1, NtriesLeft).
+
+try_listen(Port, Opts, N, Nmax) ->
+ case listen(Port, Opts) of
+ {error,eaddrinuse} when N<Nmax ->
+ timer:sleep(10*N), % Sleep 10, 20, 30,... ms
+ try_listen(Port, Opts, N+1, Nmax);
+ Other ->
+ Other
+ end.
+
+
request_ownership(LSock, SockOwner) ->
SockOwner ! {request_control,LSock,self()},
receive