Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gh 3168 sc responder crash when initiattor gone #3333

Merged
merged 2 commits into from Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions apps/aechannel/src/aesc_fsm.erl
Expand Up @@ -4901,8 +4901,15 @@ handle_common_event(E, Msg, M, #data{cur_statem_state = St} = D) ->
handle_common_event_(timeout, Info, _St, _M, D) when D#data.ongoing_update == true ->
lager:debug("timeout (~p) - recovering (~p)", [Info, D#data.error_msg_type]),
handle_recoverable_error(#{code => ?ERR_TIMEOUT}, D);
handle_common_event_(timeout, St = T, St, _, D) ->
close({timeout, T}, D);
handle_common_event_(timeout, St = T, St, _, #data{ role = Role
, opts = Opts } = D) ->
KeepRunning = maps:get(keep_running, Opts, false),
case KeepRunning andalso D#data.role =:= responder of
true ->
keep_state(D);
false ->
close({timeout, T}, D)
end;
handle_common_event_(cast, ?DISCONNECT = Msg, _St, _, #data{ channel_status = Status
, client_may_disconnect = MayDisconnect
, role = Role
Expand Down
47 changes: 41 additions & 6 deletions apps/aehttp/test/aehttp_sc_SUITE.erl
Expand Up @@ -43,6 +43,7 @@
sc_ws_leave_reestablish_wrong_fsm_id/1,
sc_ws_leave_reestablish_responder_stays/1,
sc_ws_leave_reconnect/1,
sc_ws_leave_responder_does_not_timeout/1,
sc_ws_ping_pong/1,
sc_ws_opening_ping_pong/1,
sc_ws_deposit/1,
Expand Down Expand Up @@ -183,12 +184,7 @@ groups() ->
sc_ws_close_solo,
%% fsm informs of slash potential
sc_ws_slash,
%% possible to leave and reestablish channel
sc_ws_leave_reestablish,
sc_ws_leave_reestablish_wrong_fsm_id,
sc_ws_leave_reestablish_responder_stays,
sc_ws_leave_reconnect,
sc_ws_reconnect_early,
{group, reconnects},
{group, force_progress},
{group, with_open_channel},
{group, with_meta},
Expand Down Expand Up @@ -311,6 +307,16 @@ groups() ->
{force_progress, [sequence],
[ sc_ws_force_progress_based_on_offchain_state
, sc_ws_force_progress_based_on_onchain_state
]},

%% possible to leave and reestablish channel
{reconnects, [sequence],
[ sc_ws_leave_reestablish
, sc_ws_leave_reestablish_wrong_fsm_id
, sc_ws_leave_reestablish_responder_stays
, sc_ws_leave_reconnect
, sc_ws_reconnect_early
, sc_ws_leave_responder_does_not_timeout
]}
].

Expand Down Expand Up @@ -4145,6 +4151,8 @@ log_basename(Config) ->
filename:join([Protocol, "changeable_nonce"]);
force_progress ->
filename:join([Protocol, "force_progress"]);
reconnects ->
filename:join([Protocol, "reconnects"]);
plain -> Protocol
end,
filename:join("channel_docs", SubDir).
Expand Down Expand Up @@ -5717,3 +5725,30 @@ get_channel(ChannelId) ->
{ok, _Channel} = OK -> OK;
{error, _} = Err -> Err
end.

sc_ws_leave_responder_does_not_timeout(Config0) ->
ct:log("opening channel", []),
ct:log("Config0 = ~p", [Config0]),
IdleTimeout = 1000,
Config = sc_ws_open_([{slogan, ?SLOGAN}|Config0],
#{ responder_opts => #{keep_running => true}
, timeout_idle => IdleTimeout}),
#{ responder_fsm_id := RFsmId
, responder := RConnPid } = proplists:get_value(channel_clients, Config),
ct:log("channel opened", []),
ct:log("Config = ~p", [Config]),
ct:log("*** Leaving channel ***", []),

Config1 = [{responder_leaves, false}|Config],
ct:log("Config1 = ~p", [Config1]),
ReestablishOptions = sc_ws_leave_(Config1),

timer:sleep(IdleTimeout + 100),
ping_pong(RConnPid, Config),
Config2 = reconnect_client_(ReestablishOptions, initiator,
[{reconnect_scenario, reestablish} | Config1]),
ct:log("*** Verifying that channel is operational ***", []),
ok = sc_ws_update_(Config2),
ct:log("*** Closing ... ***", []),
ok = sc_ws_close_(Config2).

@@ -0,0 +1,2 @@
* Enhances FSM behaviour: when the initiator is offline, allows the responder
to stay online waiting for it even if the timeout timer is reached.