@@ -132,7 +132,7 @@ check_connectivity(Hosts, ConnConfig) when Hosts =/= [] ->
132132-spec check_if_topic_exists ([host ()], kpro :conn_config (), topic ()) ->
133133 ok | {error , unknown_topic_or_partition | [#{host := binary (), reason := term ()}] | any ()}.
134134check_if_topic_exists (Hosts , ConnConfig , Topic ) when Hosts =/= [] ->
135- case get_metadata (Hosts , ConnConfig , Topic , _IsAutoCreateAllowed = false ) of
135+ case get_metadata (Hosts , ConnConfig , Topic , _IsAutoCreateAllowed = false , ? DEFAULT_METADATA_TIMEOUT ) of
136136 {ok , {Pid , _ }} ->
137137 ok = close_connection (Pid );
138138 {error , Errors } ->
@@ -170,11 +170,11 @@ handle_call(Call, From, #{connect := _Fun} = St) ->
170170 handle_call (Call , From , upgrade (St ));
171171handle_call (get_id , _From , #{client_id := Id } = St ) ->
172172 {reply , Id , St };
173- handle_call ({check_if_topic_exists , Topic }, _From , #{config := Config , conn_config : = ConnConfig } = St0 ) ->
173+ handle_call ({check_if_topic_exists , Topic }, _From , #{config := Config } = St0 ) ->
174174 IsAutoCreateAllowed = maps :get (allow_auto_topic_creation , Config , false ),
175175 case ensure_metadata_conn (St0 ) of
176176 {ok , #{metadata_conn := ConnPid } = St } ->
177- Timeout = maps : get ( request_timeout , ConnConfig , ? DEFAULT_METADATA_TIMEOUT ),
177+ Timeout = metadata_request_timeout ( Config ),
178178 {reply , check_if_topic_exists2 (ConnPid , Topic , Timeout , IsAutoCreateAllowed ), St };
179179 {error , Reason } ->
180180 {reply , {error , Reason }, St0 }
@@ -408,10 +408,9 @@ ensure_leader_connections(St, Group, Topic, MaxPartitions) ->
408408-spec ensure_leader_connections2 (state (), producer_group (), topic (), max_partitions ()) ->
409409 {ok , state ()} | {error , term ()}.
410410ensure_leader_connections2 (#{metadata_conn := Pid ,
411- conn_config := ConnConfig ,
412411 config := Config
413412 } = St , Group , Topic , MaxPartitions ) when is_pid (Pid ) ->
414- Timeout = metadata_request_timeout (ConnConfig ),
413+ Timeout = metadata_request_timeout (Config ),
415414 IsAutoCreateAllowed = maps :get (allow_auto_topic_creation , Config , false ),
416415 case do_get_metadata (Pid , Topic , Timeout , IsAutoCreateAllowed ) of
417416 {ok , {Brokers , PartitionMetaList }} ->
@@ -427,7 +426,8 @@ ensure_leader_connections2(#{conn_config := ConnConfig,
427426 config := Config
428427 } = St , Group , Topic , MaxPartitions ) ->
429428 IsAutoCreateAllowed = maps :get (allow_auto_topic_creation , Config , false ),
430- case get_metadata (SeedHosts , ConnConfig , Topic , IsAutoCreateAllowed , []) of
429+ Timeout = metadata_request_timeout (Config ),
430+ case get_metadata (SeedHosts , ConnConfig , Topic , IsAutoCreateAllowed , Timeout , []) of
431431 {ok , {ConnPid , {Brokers , PartitionMetaList }}} ->
432432 ensure_leader_connections3 (St , Group , Topic , ConnPid , Brokers , PartitionMetaList , MaxPartitions );
433433 {error , unknown_topic_or_partition } ->
@@ -592,21 +592,20 @@ split_config(Config) ->
592592 {ConnCfg , MyCfg } = lists :partition (Pred , maps :to_list (Config )),
593593 {maps :from_list (ConnCfg ), maps :from_list (MyCfg )}.
594594
595- -spec get_metadata ([_Host ], _ConnConfig , topic (), boolean ()) ->
595+ -spec get_metadata ([_Host ], _ConnConfig , topic (), boolean (), timeout () ) ->
596596 {ok , {pid (), term ()}} | {error , term ()}.
597- get_metadata (Hosts , _ConnectFun , _Topic , _IsAutoCreateAllowed ) when Hosts =:= [] ->
597+ get_metadata (Hosts , _ConnectFun , _Topic , _IsAutoCreateAllowed , _Timeout ) when Hosts =:= [] ->
598598 {error , no_hosts };
599- get_metadata (Hosts , ConnectFun , Topic , IsAutoCreateAllowed ) ->
600- get_metadata (Hosts , ConnectFun , Topic , IsAutoCreateAllowed , []).
599+ get_metadata (Hosts , ConnectFun , Topic , IsAutoCreateAllowed , Timeout ) ->
600+ get_metadata (Hosts , ConnectFun , Topic , IsAutoCreateAllowed , Timeout , []).
601601
602- -spec get_metadata ([_Host ], _ConnConfig , topic (), boolean (), [Error ]) ->
602+ -spec get_metadata ([_Host ], _ConnConfig , topic (), boolean (), timeout (), [Error ]) ->
603603 {ok , {pid (), term ()}} | {error , [Error ] | term ()}.
604- get_metadata ([], _ConnConfig , _Topic , _IsAutoCreateAllowed , Errors ) ->
604+ get_metadata ([], _ConnConfig , _Topic , _IsAutoCreateAllowed , _Timeout , Errors ) ->
605605 {error , Errors };
606- get_metadata ([Host | Rest ], ConnConfig , Topic , IsAutoCreateAllowed , Errors ) ->
606+ get_metadata ([Host | Rest ], ConnConfig , Topic , IsAutoCreateAllowed , Timeout , Errors ) ->
607607 case do_connect (Host , ConnConfig ) of
608608 {ok , Pid } ->
609- Timeout = metadata_request_timeout (ConnConfig ),
610609 case do_get_metadata (Pid , Topic , Timeout , IsAutoCreateAllowed ) of
611610 {ok , Result } ->
612611 {ok , {Pid , Result }};
@@ -616,7 +615,7 @@ get_metadata([Host | Rest], ConnConfig, Topic, IsAutoCreateAllowed, Errors) ->
616615 {error , Reason }
617616 end ;
618617 {error , Reason } ->
619- get_metadata (Rest , ConnConfig , Topic , IsAutoCreateAllowed , [Reason | Errors ])
618+ get_metadata (Rest , ConnConfig , Topic , IsAutoCreateAllowed , Timeout , [Reason | Errors ])
620619 end .
621620
622621-spec do_get_metadata (connection (), topic (), timeout (), boolean ()) ->
@@ -781,9 +780,9 @@ bin(X) ->
781780 Addr -> bin (Addr )
782781 end .
783782
784- metadata_request_timeout (#{request_timeout := infinity }) ->
783+ metadata_request_timeout (#{metadata_request_timeout := infinity }) ->
785784 ? DEFAULT_METADATA_TIMEOUT * 3 ;
786- metadata_request_timeout (#{request_timeout := Timeout }) ->
785+ metadata_request_timeout (#{metadata_request_timeout := Timeout }) ->
787786 Timeout ;
788787metadata_request_timeout (_ ) ->
789788 ? DEFAULT_METADATA_TIMEOUT .
0 commit comments