Skip to content

Commit

Permalink
Merge pull request #7021 from rabbitmq/dialyzer-warnings-rabbit
Browse files Browse the repository at this point in the history
Fix all dialyzer warnings in `rabbit`
  • Loading branch information
michaelklishin authored Jan 24, 2023
2 parents d4132b6 + 7c0f040 commit 8e9f0f7
Show file tree
Hide file tree
Showing 69 changed files with 230 additions and 208 deletions.
4 changes: 2 additions & 2 deletions deps/rabbit/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ xref()

plt_apps = [
"mnesia",
"runtime_tools",
] + EXTRA_APPS

plt_apps.remove("rabbitmq_prelaunch")
Expand All @@ -208,13 +209,12 @@ plt(
name = "base_plt",
apps = plt_apps,
plt = "//:base_plt",
deps = DEPS,
deps = DEPS + RUNTIME_DEPS,
)

dialyze(
dialyzer_opts = RABBITMQ_DIALYZER_OPTS,
plt = ":base_plt",
warnings_as_errors = False,
)

bats(
Expand Down
4 changes: 2 additions & 2 deletions deps/rabbit/src/pg_local.erl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ terminate(_Reason, _S) ->
%%% Pid is a member of group Name.

member_died(Ref, Pid) ->
case ets:lookup(?TABLE, {ref, Ref}) of
_ = case ets:lookup(?TABLE, {ref, Ref}) of
[{{ref, Ref}, Pid}] ->
leave_all_groups(Pid);
%% in case the key has already been removed
Expand All @@ -181,7 +181,7 @@ leave_all_groups(Pid) ->

join_group(Name, Pid) ->
Ref_Pid = {ref, Pid},
try _ = ets:update_counter(?TABLE, Ref_Pid, {3, +1})
_ = try ets:update_counter(?TABLE, Ref_Pid, {3, +1})
catch _:_ ->
Ref = erlang:monitor(process, Pid),
true = ets:insert(?TABLE, {Ref_Pid, Ref, 1}),
Expand Down
13 changes: 5 additions & 8 deletions deps/rabbit/src/rabbit.erl
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ await_startup(Node, PrintProgressReports) ->
false ->
case is_running(Node) of
true -> ok;
false -> wait_for_boot_to_start(Node),
false -> _ = _ = wait_for_boot_to_start(Node),
wait_for_boot_to_finish(Node, PrintProgressReports)
end
end.
Expand All @@ -602,7 +602,7 @@ await_startup(Node, PrintProgressReports, Timeout) ->
false ->
case is_running(Node) of
true -> ok;
false -> wait_for_boot_to_start(Node, Timeout),
false -> _ = wait_for_boot_to_start(Node, Timeout),
wait_for_boot_to_finish(Node, PrintProgressReports, Timeout)
end
end.
Expand Down Expand Up @@ -681,10 +681,7 @@ maybe_print_boot_progress(true, IterationsLeft) ->

status() ->
Version = base_product_version(),
CryptoLibInfo = case crypto:info_lib() of
[Tuple] when is_tuple(Tuple) -> Tuple;
Tuple when is_tuple(Tuple) -> Tuple
end,
[CryptoLibInfo] = crypto:info_lib(),
SeriesSupportStatus = rabbit_release_series:readable_support_status(),
S1 = [{pid, list_to_integer(os:getpid())},
%% The timeout value used is twice that of gen_server:call/2.
Expand Down Expand Up @@ -951,13 +948,13 @@ start(normal, []) ->
{ok, SupPid}
catch
throw:{error, _} = Error ->
mnesia:stop(),
_ = mnesia:stop(),
rabbit_prelaunch_errors:log_error(Error),
rabbit_prelaunch:set_stop_reason(Error),
rabbit_boot_state:set(stopped),
Error;
Class:Exception:Stacktrace ->
mnesia:stop(),
_ = mnesia:stop(),
rabbit_prelaunch_errors:log_exception(
Class, Exception, Stacktrace),
Error = {error, Exception},
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit/src/rabbit_alarm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ alert(Alertees, Source, Alert, NodeComparator) ->
internal_register(Pid, {M, F, A} = AlertMFA,
State = #alarms{alertees = Alertees}) ->
_MRef = erlang:monitor(process, Pid),
case dict:find(node(), State#alarms.alarmed_nodes) of
_ = case dict:find(node(), State#alarms.alarmed_nodes) of
{ok, Sources} -> [apply(M, F, A ++ [Pid, R, {true, true, node()}]) || R <- Sources];
error -> ok
end,
Expand Down
4 changes: 2 additions & 2 deletions deps/rabbit/src/rabbit_amqqueue.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ stat(Q) ->
rabbit_queue_type:stat(Q).

-spec pid_of(amqqueue:amqqueue()) ->
pid().
pid() | 'none'.

pid_of(Q) -> amqqueue:get_pid(Q).

Expand Down Expand Up @@ -1862,7 +1862,7 @@ forget_all_durable(Node) ->
fun () ->
Qs = mnesia:match_object(rabbit_durable_queue,
amqqueue:pattern_match_all(), write),
[forget_node_for_queue(Node, Q) ||
_ = [forget_node_for_queue(Node, Q) ||
Q <- Qs,
is_local_to_node(amqqueue:get_pid(Q), Node)],
ok
Expand Down
13 changes: 8 additions & 5 deletions deps/rabbit/src/rabbit_amqqueue_process.erl
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ recovery_barrier(BarrierPid) ->
init_with_backing_queue_state(Q, BQ, BQS,
RateTRef, Deliveries, Senders, MTC) ->
Owner = amqqueue:get_exclusive_owner(Q),
case Owner of
_ = case Owner of
none -> ok;
_ -> erlang:monitor(process, Owner)
end,
Expand Down Expand Up @@ -382,14 +382,17 @@ code_change(_OldVsn, State, _Extra) ->
maybe_notify_decorators(false, State) -> State;
maybe_notify_decorators(true, State) -> notify_decorators(State), State.

notify_decorators(Event, State) -> decorator_callback(qname(State), Event, []).
notify_decorators(Event, State) ->
_ = decorator_callback(qname(State), Event, []),
ok.

notify_decorators(State = #q{consumers = Consumers,
backing_queue = BQ,
backing_queue_state = BQS}) ->
P = rabbit_queue_consumers:max_active_priority(Consumers),
decorator_callback(qname(State), consumer_state_changed,
[P, BQ:is_empty(BQS)]).
_ = decorator_callback(qname(State), consumer_state_changed,
[P, BQ:is_empty(BQS)]),
ok.

decorator_callback(QName, F, A) ->
%% Look up again in case policy and hence decorators have changed
Expand Down Expand Up @@ -719,7 +722,7 @@ maybe_deliver_or_enqueue(Delivery = #delivery{message = Message},
send_reject_publish(Delivery, Delivered, State);
{true, 'reject-publish-dlx'} ->
%% Publish to DLX
with_dlx(
_ = with_dlx(
DLX,
fun (X) ->
rabbit_global_counters:messages_dead_lettered(maxlen, rabbit_classic_queue,
Expand Down
10 changes: 5 additions & 5 deletions deps/rabbit/src/rabbit_auth_backend_internal.erl
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ set_permissions(Username, VirtualHost, ConfigurePerm, WritePerm, ReadPerm, Actin
rabbit_log:debug("Asked to set permissions for "
"'~ts' in virtual host '~ts' to '~ts', '~ts', '~ts'",
[Username, VirtualHost, ConfigurePerm, WritePerm, ReadPerm]),
lists:map(
_ = lists:map(
fun (RegexpBin) ->
Regexp = binary_to_list(RegexpBin),
case re:compile(Regexp) of
Expand Down Expand Up @@ -538,7 +538,7 @@ set_topic_permissions(Username, VirtualHost, Exchange, WritePerm, ReadPerm, Acti
[Exchange, Username, VirtualHost, WritePerm, ReadPerm]),
WritePermRegex = rabbit_data_coercion:to_binary(WritePerm),
ReadPermRegex = rabbit_data_coercion:to_binary(ReadPerm),
lists:map(
_ = lists:map(
fun (RegexpBin) ->
case re:compile(RegexpBin) of
{ok, _} -> ok;
Expand Down Expand Up @@ -720,9 +720,9 @@ update_user_password_hash(Username, PasswordHash, Tags, Limits, User, Version) -
Username, Hash, HashingAlgorithm, ConvertedTags, Limits).

create_user_with_password(_PassedCredentialValidation = true, Username, Password, Tags, undefined, Limits, ActingUser) ->
rabbit_auth_backend_internal:add_user(Username, Password, ActingUser, Limits, Tags);
ok = rabbit_auth_backend_internal:add_user(Username, Password, ActingUser, Limits, Tags);
create_user_with_password(_PassedCredentialValidation = true, Username, Password, Tags, PreconfiguredPermissions, Limits, ActingUser) ->
rabbit_auth_backend_internal:add_user(Username, Password, ActingUser, Limits, Tags),
ok = rabbit_auth_backend_internal:add_user(Username, Password, ActingUser, Limits, Tags),
preconfigure_permissions(Username, PreconfiguredPermissions, ActingUser);
create_user_with_password(_PassedCredentialValidation = false, _Username, _Password, _Tags, _, _, _) ->
%% we don't log here because
Expand All @@ -741,7 +741,7 @@ create_user_with_password_hash(Username, PasswordHash, Tags, User, Version, Prec
preconfigure_permissions(_Username, undefined, _ActingUser) ->
ok;
preconfigure_permissions(Username, Map, ActingUser) when is_map(Map) ->
maps:map(fun(VHost, M) ->
_ = maps:map(fun(VHost, M) ->
rabbit_auth_backend_internal:set_permissions(Username, VHost,
maps:get(<<"configure">>, M),
maps:get(<<"write">>, M),
Expand Down
15 changes: 8 additions & 7 deletions deps/rabbit/src/rabbit_autoheal.erl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ init() ->
{leader_waiting, Winner, _} ->
rabbit_log:info(
"Autoheal: in progress, requesting report from ~tp", [Winner]),
send(Winner, report_autoheal_status);
_ = send(Winner, report_autoheal_status),
ok;
_ ->
ok
end,
Expand All @@ -128,7 +129,7 @@ init() ->
maybe_start(not_healing) ->
case enabled() of
true -> Leader = leader(),
send(Leader, {request_start, node()}),
_ = send(Leader, {request_start, node()}),
rabbit_log:info("Autoheal request sent to ~tp", [Leader]),
not_healing;
false -> not_healing
Expand Down Expand Up @@ -216,7 +217,7 @@ handle_msg({request_start, Node},
case node() =:= Winner of
true -> handle_msg({become_winner, Losers},
not_healing, Partitions);
false -> send(Winner, {become_winner, Losers}),
false -> _ = send(Winner, {become_winner, Losers}),
{leader_waiting, Winner, Losers}
end
end;
Expand Down Expand Up @@ -272,7 +273,7 @@ handle_msg(report_autoheal_status, not_healing, _Partitions) ->
%% winner). This happens when the leader is a loser and it just
%% restarted. We are in the "not_healing" state, so the previous
%% autoheal process ended: let's tell this to the leader.
send(leader(), {autoheal_finished, node()}),
_ = send(leader(), {autoheal_finished, node()}),
not_healing;

handle_msg(report_autoheal_status, State, _Partitions) ->
Expand Down Expand Up @@ -329,7 +330,7 @@ winner_finish(Notify) ->
%% losing nodes before sending the "autoheal_safe_to_start" signal.
wait_for_mnesia_shutdown(Notify),
[{rabbit_outside_app_process, N} ! autoheal_safe_to_start || N <- Notify],
send(leader(), {autoheal_finished, node()}),
_ = send(leader(), {autoheal_finished, node()}),
not_healing.

%% This improves the previous implementation, but could still potentially enter an infinity
Expand All @@ -355,7 +356,7 @@ wait_for_supervisors(Monitors) ->
AliveLosers = [Node || {_, Node} <- pmon:monitored(Monitors)],
rabbit_log:info("Autoheal: mnesia in nodes ~tp is still up, sending "
"winner notification again to these ", [AliveLosers]),
[send(L, {winner_is, node()}) || L <- AliveLosers],
_ = [send(L, {winner_is, node()}) || L <- AliveLosers],
wait_for_mnesia_shutdown(AliveLosers)
end
end.
Expand Down Expand Up @@ -449,7 +450,7 @@ stop_partition(Losers) ->
%% give up.
Down = Losers -- rabbit_node_monitor:alive_rabbit_nodes(Losers),
case Down of
[] -> [send(L, {winner_is, node()}) || L <- Losers],
[] -> _ = [send(L, {winner_is, node()}) || L <- Losers],
{winner_waiting, Losers, Losers};
_ -> abort(Down, Losers)
end.
14 changes: 8 additions & 6 deletions deps/rabbit/src/rabbit_binding.erl
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ new(Src, RoutingKey, Dst, Arguments) ->
recover() ->
rabbit_misc:execute_mnesia_transaction(
fun () ->
mnesia:lock({table, rabbit_durable_route}, read),
mnesia:lock({table, rabbit_semi_durable_route}, write),
_ = mnesia:lock({table, rabbit_durable_route}, read),
_ = mnesia:lock({table, rabbit_semi_durable_route}, write),
Routes = rabbit_misc:dirty_read_all(rabbit_durable_route),
Fun = fun(Route) ->
mnesia:dirty_write(rabbit_semi_durable_route, Route)
Expand Down Expand Up @@ -545,7 +545,7 @@ remove_routes(Routes, ShouldIndexTable) ->
R <- SemiDurableRoutes],
[ok = sync_route(R, false, false, ShouldIndexTable, fun delete/3) ||
R <- RamOnlyRoutes],
case ShouldIndexTable of
_ = case ShouldIndexTable of
B when is_boolean(B) ->
ok;
undefined ->
Expand Down Expand Up @@ -603,8 +603,9 @@ remove_for_destination(DstName, OnlyDurable, Fun) ->
lock_resource(Name) -> lock_resource(Name, write).

lock_resource(Name, LockKind) ->
mnesia:lock({global, Name, mnesia:table_info(rabbit_route, where_to_write)},
LockKind).
_ = mnesia:lock({global, Name, mnesia:table_info(rabbit_route, where_to_write)},
LockKind),
ok.

%% Requires that its input binding list is sorted in exchange-name
%% order, so that the grouping of bindings (for passing to
Expand Down Expand Up @@ -739,7 +740,8 @@ process_deletions(Deletions, ActingUser) ->
del_notify(Bs, ActingUser) -> [rabbit_event:notify(
binding_deleted,
info(B) ++ [{user_who_performed_action, ActingUser}])
|| B <- Bs].
|| B <- Bs],
ok.

x_callback(Serial, X, F, Bs) ->
ok = rabbit_exchange:callback(X, F, Serial, [X, Bs]).
Expand Down
14 changes: 7 additions & 7 deletions deps/rabbit/src/rabbit_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ emit_info(PidList, InfoItems, Ref, AggregatorPid) ->
-spec refresh_config_local() -> 'ok'.

refresh_config_local() ->
rabbit_misc:upmap(
_ = rabbit_misc:upmap(
fun (C) ->
try
gen_server2:call(C, refresh_config, infinity)
Expand All @@ -454,7 +454,7 @@ refresh_config_local() ->
ok.

refresh_interceptors() ->
rabbit_misc:upmap(
_ = rabbit_misc:upmap(
fun (C) ->
try
gen_server2:call(C, refresh_interceptors, ?REFRESH_TIMEOUT)
Expand Down Expand Up @@ -779,7 +779,7 @@ handle_cast({queue_event, QRef, Evt},
%% Do not nack the "rejected" messages.
State2 = record_confirms(ConfirmMXs,
State1#ch{unconfirmed = UC1}),
erase_queue_stats(QRef),
_ = erase_queue_stats(QRef),
noreply_coalesce(
State2#ch{queue_states = rabbit_queue_type:remove(QRef, QueueStates0)});
{protocol_error, Type, Reason, ReasonArgs} ->
Expand Down Expand Up @@ -830,7 +830,7 @@ handle_info({'DOWN', _MRef, process, QPid, Reason},
%% Do not nack the "rejected" messages.
State2 = record_confirms(ConfirmMXs,
State1#ch{unconfirmed = UC1}),
erase_queue_stats(QRef),
_ = erase_queue_stats(QRef),
noreply_coalesce(
State2#ch{queue_states = rabbit_queue_type:remove(QRef, State2#ch.queue_states)})
end;
Expand Down Expand Up @@ -2233,7 +2233,7 @@ deliver_to_queues({Delivery = #delivery{message = Message = #basic_message{ex
%% Actions must be processed after registering confirms as actions may
%% contain rejections of publishes
State = handle_queue_actions(Actions, State1#ch{queue_states = QueueStates}),
case rabbit_event:stats_level(State, #ch.stats_timer) of
_ = case rabbit_event:stats_level(State, #ch.stats_timer) of
fine ->
?INCR_STATS(exchange_stats, XName, 1, publish),
[?INCR_STATS(queue_exchange_stats, {QName, XName}, 1, publish)
Expand Down Expand Up @@ -2717,7 +2717,7 @@ handle_method(#'exchange.declare'{exchange = ExchangeNameBin,
X = case rabbit_exchange:lookup(ExchangeName) of
{ok, FoundX} -> FoundX;
{error, not_found} ->
check_name('exchange', strip_cr_lf(ExchangeNameBin)),
_ = check_name('exchange', strip_cr_lf(ExchangeNameBin)),
AeKey = <<"alternate-exchange">>,
case rabbit_misc:r_arg(VHostPath, exchange, Args, AeKey) of
undefined -> ok;
Expand Down Expand Up @@ -2776,7 +2776,7 @@ handle_deliver0(ConsumerTag, AckRequired,
_ ->
ok = rabbit_writer:send_command(WriterPid, Deliver, Content)
end,
case GCThreshold of
_ = case GCThreshold of
undefined -> ok;
_ -> rabbit_basic:maybe_gc_large_msg(Content, GCThreshold)
end,
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit/src/rabbit_channel_interceptor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ check_no_overlap(Mods) ->

%% Check no non-empty pairwise intersection in a list of sets
check_no_overlap1(Sets) ->
lists:foldl(fun(Set, Union) ->
_ = lists:foldl(fun(Set, Union) ->
Is = sets:intersection(Set, Union),
case sets:size(Is) of
0 -> ok;
Expand Down
Loading

0 comments on commit 8e9f0f7

Please sign in to comment.