Skip to content

Commit 2253f67

Browse files
authored
Merge pull request #492 from kafka4beam/fix/timeout-brod-client
safe_gen_call catches more exit exceptions
2 parents a9c193c + 32d09d6 commit 2253f67

File tree

7 files changed

+42
-23
lines changed

7 files changed

+42
-23
lines changed

changelog.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
* 3.16.2
2+
* Update kafka_protocol from 4.0.1 to 4.0.3.
3+
Prior to this change the actual time spent in establishing a
4+
Kafka connection might be longer than desired due to the timeout
5+
being used in SSL upgrade (if enabled), then API version query.
6+
This has been fixed by turning the given timeout config
7+
into a deadline, and the sub-steps will try to meet the deadline.
8+
see more details here: https://github.com/kafka4beam/kafka_protocol/pull/9
9+
* Catch `timeout` and other `DOWN` reasons when making `gen_server` call to
10+
`brod_client`, `brod_consumer` and producer/consumer supervisor,
11+
and return as `Reason` in `{error, Reason}`.
12+
Previously only `noproc` reaon is caught. (#492)
213
* Propagate `connect_timeout` config to `kpro` API functions as `timeout` arg
314
affected APIs: connect_group_coordinator, create_topics, delete_topics,
4-
resolve_offset, fetch, fold, fetch_committed_offsets
15+
resolve_offset, fetch, fold, fetch_committed_offsets (#458)
16+
* Fix bad field name in group describe request (#486)
517
* 3.16.1
618
* Fix `brod` script in `brod-cli` in release.
719
* Support `rebalance_timeout` consumer group option

rebar.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{deps, [ {supervisor3, "1.1.11"}
2-
, {kafka_protocol, "4.0.1"}
2+
, {kafka_protocol, "4.0.3"}
33
, {snappyer, "1.2.8"}
44
]}.
55
{edoc_opts, [{preprocess, true}, {macros, [{build_brod_cli, true}]}]}.

src/brod.erl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ get_partitions_count(Client, Topic) ->
455455
-spec get_consumer(client(), topic(), partition()) ->
456456
{ok, pid()} | {error, Reason}
457457
when Reason :: client_down
458-
| {consumer_down, noproc}
458+
| {client_down, any()}
459+
| {consumer_down, any()}
459460
| {consumer_not_found, topic()}
460461
| {consumer_not_found, topic(), partition()}.
461462
get_consumer(Client, Topic, Partition) ->
@@ -465,7 +466,8 @@ get_consumer(Client, Topic, Partition) ->
465466
-spec get_producer(client(), topic(), partition()) ->
466467
{ok, pid()} | {error, Reason}
467468
when Reason :: client_down
468-
| {producer_down, noproc}
469+
| {client_down, any()}
470+
| {producer_down, any()}
469471
| {producer_not_found, topic()}
470472
| {producer_not_found, topic(), partition()}.
471473
get_producer(Client, Topic, Partition) ->

src/brod_client.erl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@
8383
| ?CONSUMER_KEY(topic(), partition()).
8484

8585
-type get_producer_error() :: client_down
86-
| {producer_down, noproc}
86+
| {client_down, any()}
87+
| {producer_down, any()}
8788
| {producer_not_found, topic()}
88-
| { producer_not_found
89-
, topic()
90-
, partition()}.
89+
| {producer_not_found, topic(), partition()}.
9190

9291
-type get_consumer_error() :: client_down
93-
| {consumer_down, noproc}
92+
| {client_down, any()}
93+
| {consumer_down, any()}
9494
| {consumer_not_found, topic()}
9595
| {consumer_not_found, topic(), partition()}.
9696

@@ -829,16 +829,20 @@ ensure_partition_workers(TopicName, State, F) ->
829829
end
830830
end).
831831

832-
%% Catch noproc exit exception when making gen_server:call.
832+
%% Catches exit exceptions when making gen_server:call.
833833
-spec safe_gen_call(pid() | atom(), Call, Timeout) -> Return
834834
when Call :: term(),
835835
Timeout :: infinity | integer(),
836-
Return :: ok | {ok, term()} | {error, client_down | term()}.
836+
Return :: ok | {ok, term()} | {error, Reason},
837+
Reason :: client_down | {client_down, any()} | any().
837838
safe_gen_call(Server, Call, Timeout) ->
838839
try
839840
gen_server:call(Server, Call, Timeout)
840-
catch exit : {noproc, _} ->
841-
{error, client_down}
841+
catch
842+
exit : {noproc, _} ->
843+
{error, client_down};
844+
exit : {Reason, _} ->
845+
{error, {client_down, Reason}}
842846
end.
843847

844848
-spec kf(kpro:field_name(), kpro:struct()) -> kpro:field_value().

src/brod_consumer.erl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -794,16 +794,17 @@ reset_buffer(#state{ pending_acks = #pending_acks{queue = Queue}
794794
, last_req_ref = ?undef
795795
}.
796796

797-
%% Catch noproc exit exception when making gen_server:call.
797+
%% Catch exit exceptions when making gen_server:call.
798798
-spec safe_gen_call(pid() | atom(), Call, Timeout) -> Return
799799
when Call :: term(),
800800
Timeout :: infinity | integer(),
801-
Return :: ok | {ok, term()} | {error, consumer_down | term()}.
801+
Return :: ok | {ok, term()} | {error, any()}.
802802
safe_gen_call(Server, Call, Timeout) ->
803803
try
804804
gen_server:call(Server, Call, Timeout)
805-
catch exit : {noproc, _} ->
806-
{error, consumer_down}
805+
catch
806+
exit : {Reason, _} ->
807+
{error, Reason}
807808
end.
808809

809810
%% Init payload connection regardless of subscriber state.

src/brod_consumers_sup.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ stop_consumer(SupPid, TopicName) ->
6767
{ok, pid()} | {error, Reason} when
6868
Reason :: {consumer_not_found, brod:topic()}
6969
| {consumer_not_found, brod:topic(), brod:partition()}
70-
| {consumer_down, noproc}.
70+
| {consumer_down, any()}.
7171
find_consumer(SupPid, Topic, Partition) ->
7272
case supervisor3:find_child(SupPid, Topic) of
7373
[] ->
@@ -83,8 +83,8 @@ find_consumer(SupPid, Topic, Partition) ->
8383
[Pid] ->
8484
{ok, Pid}
8585
end
86-
catch exit : {noproc, _} ->
87-
{error, {consumer_down, noproc}}
86+
catch exit : {Reason, _} ->
87+
{error, {consumer_down, Reason}}
8888
end
8989
end.
9090

src/brod_producers_sup.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ stop_producer(SupPid, TopicName) ->
7171
{ok, pid()} | {error, Reason} when
7272
Reason :: {producer_not_found, brod:topic()}
7373
| {producer_not_found, brod:topic(), brod:partition()}
74-
| {producer_down, noproc}.
74+
| {producer_down, any()}.
7575
find_producer(SupPid, Topic, Partition) ->
7676
case supervisor3:find_child(SupPid, Topic) of
7777
[] ->
@@ -87,8 +87,8 @@ find_producer(SupPid, Topic, Partition) ->
8787
[Pid] ->
8888
{ok, Pid}
8989
end
90-
catch exit : {noproc, _} ->
91-
{error, {producer_down, noproc}}
90+
catch exit : {Reason, _} ->
91+
{error, {producer_down, Reason}}
9292
end
9393
end.
9494

0 commit comments

Comments
 (0)