@@ -50,6 +50,16 @@ ensure_present(ClientId, Hosts, Config) ->
5050% % @doc Ensure client stopped and deleted under supervisor.
5151-spec ensure_absence (wolff :client_id ()) -> ok .
5252ensure_absence (ClientId ) ->
53+ % % This receive may take 5s because the child spec's shutdown policy is to kill after 5s
54+ % % To ensure the cleanup is complete, spawn a process to do it, in case the caller
55+ % % gets killed while waiting for shutdown.
56+ {Pid , Mref } = erlang :spawn_monitor (fun () -> do_ensure_absence (ClientId ) end ),
57+ receive
58+ {'DOWN' , Mref , process , Pid , _ } ->
59+ ok
60+ end .
61+
62+ do_ensure_absence (ClientId ) ->
5363 case supervisor :terminate_child (? SUPERVISOR , ClientId ) of
5464 ok -> ok = supervisor :delete_child (? SUPERVISOR , ClientId );
5565 {error , not_found } -> ok
@@ -79,7 +89,8 @@ child_spec(ClientId, Hosts, Config) ->
7989 start => {wolff_client , start_link , [ClientId , Hosts , Config ]},
8090 restart => transient ,
8191 type => worker ,
82- modules => [wolff_client ]
92+ modules => [wolff_client ],
93+ shutdown => 5000
8394 }.
8495
8596% % @doc Create a ets table which is used for client registration.
0 commit comments