Skip to content

Commit

Permalink
Handle econnrefused gracefully
Browse files Browse the repository at this point in the history
When remote HTTP server is down, in h2_connection:init/1 Transport:connect will return econnrefused. As this call is handled in h2_connection:init/1, current code returns {stop,econnrefused}. Although this is handled gracefully by clients, we do see an CRASH report saying that:

`[error] CRASH REPORT Process <0.2985.0> with 0 neighbours exited with reason: econnrefused in gen_statem:init_result/6 line 728`

gen_statem:init origin routine would have called exit with a reason code other than normal and this triggers the CRASH report. If the gen_statem module has returned {stop, {shutdown,Reason}}, the gen_statem process would call Module:terminate/1 and exit appropriately without a crash report.
  • Loading branch information
vasu-dasari committed May 12, 2019
1 parent c96deaf commit e0ef922
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/h2_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,8 @@ init({client, Transport, Host, Port, SSLOptions, Http2Settings, ConnectionSettin
handshake,
send_settings(Http2Settings, InitialState),
4500};
{error, econnrefused} ->
ignore;
{error, Reason} ->
{stop, Reason}
{stop, {shutdown,Reason}}
end;
init({client_ssl_upgrade, Host, Port, InitialMessage, SSLOptions, Http2Settings, ConnectionSettings}) ->
case gen_tcp:connect(Host, Port, [{active, false}]) of
Expand All @@ -221,10 +219,8 @@ init({client_ssl_upgrade, Host, Port, InitialMessage, SSLOptions, Http2Settings,
handshake,
send_settings(Http2Settings, InitialState),
4500};
{error, econnrefused} ->
ignore;
{error, Reason} ->
{stop, Reason}
{stop, {shutdown,Reason}}
end;
{error, Reason} ->
{stop, Reason}
Expand Down

0 comments on commit e0ef922

Please sign in to comment.