From e8467bb3ce42c04a135f040bf2c6b8271c53ec59 Mon Sep 17 00:00:00 2001 From: David Ansari Date: Thu, 11 Apr 2024 15:26:23 +0200 Subject: [PATCH] Cancel timer async to improve performance on the critical path --- src/cowboy_clock.erl | 2 +- src/cowboy_http.erl | 2 +- src/cowboy_websocket.erl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cowboy_clock.erl b/src/cowboy_clock.erl index e2cdf62d9..b48439442 100644 --- a/src/cowboy_clock.erl +++ b/src/cowboy_clock.erl @@ -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}), diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl index 9c92ec5a2..b9cfb0eef 100644 --- a/src/cowboy_http.erl +++ b/src/cowboy_http.erl @@ -327,7 +327,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 -> diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl index 3cc4d303c..f1853a68e 100644 --- a/src/cowboy_websocket.erl +++ b/src/cowboy_websocket.erl @@ -377,7 +377,7 @@ before_loop(State, HandlerState, ParseState) -> loop_timeout(State=#state{opts=Opts, timeout_ref=PrevRef}) -> _ = 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 ->