Skip to content

Commit

Permalink
Merge branch 'hans/ssh/acceptor_crash/ERIERL-726/OTP-17764' into main…
Browse files Browse the repository at this point in the history
…t-24

* hans/ssh/acceptor_crash/ERIERL-726/OTP-17764:
  ssh: Handle unexpected errors in acceptor loop
  • Loading branch information
Erlang/OTP committed Nov 21, 2021
2 parents 2a89aa5 + aeed9b9 commit ca99d30
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions lib/ssh/src/ssh_acceptor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,27 @@ request_ownership(LSock, SockOwner) ->

%%%----------------------------------------------------------------
acceptor_loop(Port, Address, Opts, ListenSocket, AcceptTimeout, SystemSup) ->
case accept(ListenSocket, AcceptTimeout, Opts) of
{ok,Socket} ->
{ok, {FromIP,FromPort}} = inet:peername(Socket), % Just in case of error in next line:
case handle_connection(SystemSup, Address, Port, Opts, Socket) of
{error,Error} ->
catch close(Socket, Opts),
handle_error(Error, Address, Port, FromIP, FromPort);
_ ->
ok
end;
{error,Error} ->
handle_error(Error, Address, Port)
try
case accept(ListenSocket, AcceptTimeout, Opts) of
{ok,Socket} ->
case inet:peername(Socket) of
{ok, {FromIP,FromPort}} ->
case handle_connection(SystemSup, Address, Port, Opts, Socket) of
{error,Error} ->
catch close(Socket, Opts),
handle_error(Error, Address, Port, FromIP, FromPort);
_ ->
ok
end;
{error,Error} ->
handle_error(Error, Address, Port)
end;
{error,Error} ->
handle_error(Error, Address, Port)
end
catch
Class:Err:Stack ->
handle_error({error, {unhandled,Class,Err,Stack}}, Address, Port)
end,
?MODULE:acceptor_loop(Port, Address, Opts, ListenSocket, AcceptTimeout, SystemSup).

Expand Down

0 comments on commit ca99d30

Please sign in to comment.