5757 % % but we need to find connection by {topic(), partition()}
5858 leaders => #{{topic (), partition ()} => connection ()},
5959 % % Reference counting so we may drop connection metadata when no longer required.
60- known_topics := #{topic () => #{producer_group () => true }}
60+ known_topics := #{topic () => #{producer_group () => true }},
61+ owner := pid ()
6162 }.
6263
6364-define (DEFAULT_METADATA_TIMEOUT , 10000 ).
7879start_link (ClientId , Hosts , Config ) ->
7980 {ConnCfg0 , MyCfg } = split_config (Config ),
8081 ConnCfg = ConnCfg0 #{client_id => ClientId },
82+ Owner = self (),
8183 St = #{client_id => ClientId ,
8284 seed_hosts => Hosts ,
8385 config => MyCfg ,
@@ -86,7 +88,8 @@ start_link(ClientId, Hosts, Config) ->
8688 metadata_conn => not_initialized ,
8789 metadata_ts => #{},
8890 leaders => #{},
89- known_topics => #{}
91+ known_topics => #{},
92+ owner => Owner
9093 },
9194 case maps :get (reg_name , Config , false ) of
9295 false -> gen_server :start_link (? MODULE , St , []);
@@ -199,7 +202,13 @@ handle_call(Call, _From, St) ->
199202 {reply , {error , {unknown_call , Call }}, St }.
200203
201204handle_info ({'EXIT' , Pid , Reason }, St ) ->
202- {noreply , flush_exit_signals (St , Pid , Reason )};
205+ % % Check if this is a shutdown signal from the supervisor
206+ case erlang :whereis (wolff_client_sup ) of
207+ Pid when Reason =:= shutdown ->
208+ {stop , shutdown , St };
209+ _ ->
210+ {noreply , flush_exit_signals (St , Pid , Reason )}
211+ end ;
203212handle_info (_Info , St ) ->
204213 {noreply , upgrade (St )}.
205214
@@ -243,7 +252,7 @@ handle_cast(_Cast, St) ->
243252code_change (_OldVsn , St , _Extra ) ->
244253 {ok , St }.
245254
246- terminate (_ , #{client_id := ClientID , conns := Conns } = St ) ->
255+ terminate (_Reason , #{client_id := ClientID , conns := Conns } = St ) ->
247256 ok = wolff_client_sup :deregister_client (ClientID ),
248257 MetadataConn = maps :get (metadata_conn , St , none ),
249258 ok = close_connections (Conns ),
@@ -307,9 +316,9 @@ close_connections(Conns, Topic) ->
307316 end ,
308317 do_close_connections (maps :to_list (Conns ), Pred , #{}).
309318
310- flush_exit_signals (St0 ) ->
319+ flush_exit_signals (#{ owner : = Owner } = St0 ) ->
311320 receive
312- {'EXIT' , Pid , Reason } ->
321+ {'EXIT' , Pid , Reason } when Pid =/= Owner ->
313322 flush_exit_signals (St0 , Pid , Reason )
314323 after
315324 0 ->
0 commit comments