Skip to content

Commit

Permalink
Cancel timers async
Browse files Browse the repository at this point in the history
Where it wasn't already async. To slightly improve performance.
  • Loading branch information
ansd authored and essen committed Jan 24, 2025
1 parent 2531b26 commit fcab905
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cowboy_clock.erl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ handle_cast(_Msg, State) ->
-spec handle_info(any(), State) -> {noreply, State} when State::#state{}.
handle_info(update, #state{universaltime=Prev, rfc1123=B1, tref=TRef0}) ->
%% Cancel the timer in case an external process sent an update message.
_ = erlang:cancel_timer(TRef0),
_ = erlang:cancel_timer(TRef0, [{async, true}, {info, false}]),
T = erlang:universaltime(),
B2 = update_rfc1123(B1, Prev, T),
ets:insert(?MODULE, {rfc1123, B2}),
Expand Down
2 changes: 1 addition & 1 deletion src/cowboy_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ cancel_timeout(State=#state{timer=TimerRef}) ->
_ ->
%% Do a synchronous cancel and remove the message if any
%% to avoid receiving stray messages.
_ = erlang:cancel_timer(TimerRef),
_ = erlang:cancel_timer(TimerRef, [{async, false}, {info, false}]),
receive
{timeout, TimerRef, _} -> ok
after 0 ->
Expand Down
2 changes: 1 addition & 1 deletion src/cowboy_websocket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ set_idle_timeout(State=#state{opts=Opts, timeout_ref=PrevRef}, TimeoutNum) ->
%% options are changed dynamically.
_ = case PrevRef of
undefined -> ignore;
PrevRef -> erlang:cancel_timer(PrevRef)
PrevRef -> erlang:cancel_timer(PrevRef, [{async, true}, {info, false}])
end,
case maps:get(idle_timeout, Opts, 60000) of
infinity ->
Expand Down

0 comments on commit fcab905

Please sign in to comment.