Skip to content

Commit

Permalink
use generic timeout, and timeout from env
Browse files Browse the repository at this point in the history
  • Loading branch information
abijr committed Mar 4, 2024
1 parent 3056c15 commit 769c9d7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/erlmld_wrk_statem.erl
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,11 @@ handle_event(?INTERNAL,
end,
ok = gen_tcp:send(Socket, [IoData, "\n"]),
case NextReadKind of
Kind when Kind == ?SHUTDOWN; Kind == ?SHUTDOWN_CHECKPOINT ->
Kind when Kind == ?SHUTDOWN ->
%% next state is waiting for the MLD to close the connection.
%% But it might not happen, so we'll close it ourselves after a timeout.
%% Note that this timeout gets cancelled if we have state changes before it fires.
{next_state, {?PEER_READ, Kind}, activate(Data), [{state_timeout, 5000, shutdown}]};
Timeout = application:get_env(erlmld, shutdown_timeout, 5000),
{next_state, {?PEER_READ, Kind}, activate(Data), [{{timeout, shutdown}, Timeout, shutdown}]};
_ ->
{next_state, {?PEER_READ, NextReadKind}, activate(Data)}
end;
Expand All @@ -476,7 +476,8 @@ handle_event(info, {tcp, _Socket, _Bin}, _State, _Data) ->
handle_event(info, Message, _State, #data{worker_state = WorkerState}) ->
error_logger:error_msg("~p ignoring unexpected message ~p~n", [WorkerState, Message]),
keep_state_and_data;
handle_event(state_timeout, shutdown, _State, _Data) ->

handle_event({timeout, shutdown}, shutdown, _State, _Data) ->
{stop, {error, shutdown_timeout}}.

%%%===================================================================
Expand Down

0 comments on commit 769c9d7

Please sign in to comment.