From a2c959e0b45437c7ecab8a4a511ca1d9f25edf32 Mon Sep 17 00:00:00 2001 From: Jan Uhlig Date: Thu, 4 Jul 2024 10:34:42 +0200 Subject: [PATCH] Use erpc:call instead of custom call mechanism --- src/ranch.erl | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/ranch.erl b/src/ranch.erl index d909afd735..cb37690c52 100644 --- a/src/ranch.erl +++ b/src/ranch.erl @@ -193,16 +193,11 @@ start_error(_, Error) -> Error. -spec stop_listener(ref()) -> ok | {error, not_found}. stop_listener(Ref) -> - Parent = self(), - Tag = make_ref(), - {StopperPid, StopperMon} = spawn_monitor(fun() -> Parent ! {Tag, stop_listener1(Ref)} end), - receive - {Tag, Result} -> - demonitor(StopperMon, [flush]), - Result; - {'DOWN', StopperMon, process, StopperPid, Error} -> - {error, Error} - end. + %% We need to provide an integer timeout to erpc:call, + %% otherwise the function will be executed in the calling + %% process. 16#ffffffff is as close to 'infinity' as we + %% can get. + erpc:call(node(), fun() -> stop_listener1(Ref) end, 16#ffffffff). stop_listener1(Ref) -> TransportAndOpts = maybe_get_transport_and_opts(Ref),