rabbitmq / rabbitmq-common

Common library used by rabbitmq-server and rabbitmq-erlang-client
Other
66 stars 112 forks source link

Dialyzer warns some undefined functions #320

Closed mopp closed 5 years ago

mopp commented 5 years ago

We have an application with rebar3. We got the warnings in the case of dialyzer configuration like below. The environment is Erlang/OTP 18.

{dialyzer, [{plt_apps, all_deps},
            {warnings, [error_handling,
                        race_conditions,
                        unknown,
                        unmatched_returns,
                        no_improper_lists]}]}.
0: Unknown type rabbit_amqqueue:name/0
0: Unknown type rabbit_binding:key/0
0: Unknown type rabbit_exchange:name/0
0: Unknown type rabbit_exchange:type/0
0: Unknown type rabbit_framing:amqp_class_id/0
0: Unknown type rabbit_framing:amqp_exception/0
0: Unknown type rabbit_framing:amqp_method_name/0
0: Unknown type rabbit_framing:amqp_property_record/0
0: Unknown type rabbit_framing:amqp_table/0
0: Unknown type rabbit_guid:guid/0
0: Unknown type rabbit_networking:hostname/0
0: Unknown type rabbit_networking:ip_port/0
0: Unknown type rabbit_router:routing_key/0
0: Unknown type set:set/0

I tried to solve them. Then, I found that these types are defined in simplegeo/rabbitmq-server.

How to solve them ?

michaelklishin commented 5 years ago

Some of the types may be defined in https://github.com/rabbitmq/rabbitmq-server, which is the canonical fork. The one linked to above is ~ 8 years old.

We are working on reducing the inter-dependencies between this library and rabbitmq-server. I believe Dialyzer in master already passes on a supported Erlang version (21.3+).

mopp commented 5 years ago

Thanks for your comment. We refers this library via amqp_client | Hex.

We are working on reducing the inter-dependencies between this library and rabbitmq-server. I believe Dialyzer in master already passes on a supported Erlang version (21.3+).

I got the warnings still on master (f6f154f2d906a483a7fb142d324adef96ad8da7f) branch and Erlang/OTP 22.0 RC2.

> make dialyze
make: elixir: Command not found
make[1]: Entering directory '/Users/mopp/repos/rabbitmq-common/deps/rabbitmq_codegen'
make[1]: Leaving directory '/Users/mopp/repos/rabbitmq-common/deps/rabbitmq_codegen'
make[1]: Entering directory '/Users/mopp/repos/rabbitmq-common/deps/lager'
 DEP    goldrush
make[2]: Entering directory '/Users/mopp/repos/rabbitmq-common/deps/goldrush'
 DEPEND goldrush.d
 ERLC   glc.erl glc_code.erl glc_lib.erl glc_ops.erl glc_run.erl gr_app.erl gr_context.erl gr_counter.erl gr_counter_sup.erl gr_manager.erl gr_manager_sup.erl gr_param.erl gr_param_sup.erl gr_sup.erl gre.erl
 APP    goldrush.app.src
make[2]: Leaving directory '/Users/mopp/repos/rabbitmq-common/deps/goldrush'
 DEPEND lager.d
 ERLC   error_logger_lager_h.erl lager.erl lager_app.erl lager_backend_throttle.erl lager_common_test_backend.erl lager_config.erl lager_console_backend.erl lager_crash_log.erl lager_default_formatter.erl lager_file_backend.erl lager_format.erl lager_handler_watcher.erl lager_handler_watcher_sup.erl lager_manager_killer.erl lager_msg.erl lager_rotator_behaviour.erl lager_rotator_default.erl lager_stdlib.erl lager_sup.erl lager_transform.erl lager_trunc_io.erl lager_util.erl
 APP    lager.app.src
make[1]: Leaving directory '/Users/mopp/repos/rabbitmq-common/deps/lager'
make[1]: Entering directory '/Users/mopp/repos/rabbitmq-common/deps/jsx'
 DEPEND jsx.d
 ERLC   jsx.erl jsx_config.erl jsx_consult.erl jsx_decoder.erl jsx_encoder.erl jsx_parser.erl jsx_to_json.erl jsx_to_term.erl jsx_verify.erl
Old inliner: threshold=0 functions=[{doublequote,5},
                                    {singlequote,5},
                                    {maybe_replace,2},
                                    {format_number,1},
                                    {handle_event,3}]
 APP    jsx.app.src
make[1]: Leaving directory '/Users/mopp/repos/rabbitmq-common/deps/jsx'
make[1]: Entering directory '/Users/mopp/repos/rabbitmq-common/deps/ranch'
 DEPEND ranch.d
 ERLC   ranch.erl ranch_acceptor.erl ranch_acceptors_sup.erl ranch_app.erl ranch_conns_sup.erl ranch_crc32c.erl ranch_listener_sup.erl ranch_protocol.erl ranch_proxy_header.erl ranch_server.erl ranch_ssl.erl ranch_sup.erl ranch_tcp.erl ranch_transport.erl
 APP    ranch.app.src
make[1]: Leaving directory '/Users/mopp/repos/rabbitmq-common/deps/ranch'
make[1]: Entering directory '/Users/mopp/repos/rabbitmq-common/deps/recon'
 DEPEND recon.d
 ERLC   recon.erl recon_alloc.erl recon_lib.erl recon_rec.erl recon_trace.erl
Old inliner: threshold=0 functions=[{insert,2},{merge,2}]
 APP    recon.app.src
make[1]: Leaving directory '/Users/mopp/repos/rabbitmq-common/deps/recon'
 GEN    include/rabbit_framing.hrl
 GEN    src/rabbit_framing_amqp_0_8.erl
 GEN    src/rabbit_framing_amqp_0_9_1.erl
 DEPEND rabbit_common.d
make[1]: elixir: Command not found
 ERLC   app_utils.erl code_version.erl credit_flow.erl delegate.erl delegate_sup.erl file_handle_cache.erl file_handle_cache_stats.erl gen_server2.erl lager_forwarder_backend.erl mirrored_supervisor.erl mnesia_sync.erl pmon.erl priority_queue.erl rabbit_amqp_connection.erl rabbit_amqqueue_common.erl rabbit_auth_backend_dummy.erl rabbit_auth_mechanism.erl rabbit_authn_backend.erl rabbit_authz_backend.erl rabbit_basic_common.erl rabbit_binary_generator.erl rabbit_binary_parser.erl rabbit_cert_info.erl rabbit_channel_common.erl rabbit_command_assembler.erl rabbit_control_misc.erl rabbit_core_metrics.erl rabbit_data_coercion.erl rabbit_error_logger_handler.erl rabbit_event.erl rabbit_exchange_type.erl rabbit_framing_amqp_0_8.erl rabbit_framing_amqp_0_9_1.erl rabbit_heartbeat.erl rabbit_http_util.erl rabbit_json.erl rabbit_log.erl rabbit_log_ra_shim.erl rabbit_misc.erl rabbit_msg_store_index.erl rabbit_net.erl rabbit_nodes_common.erl rabbit_numerical.erl rabbit_password_hashing.erl rabbit_pbe.erl rabbit_peer_discovery_backend.erl rabbit_policy_validator.erl rabbit_pretty_stdout.erl rabbit_queue_collector_common.erl rabbit_registry.erl rabbit_registry_class.erl rabbit_resource_monitor_misc.erl rabbit_runtime.erl rabbit_runtime_parameter.erl rabbit_semver.erl rabbit_semver_parser.erl rabbit_ssl_options.erl rabbit_types.erl rabbit_writer.erl supervisor2.erl vm_memory_monitor.erl worker_pool.erl worker_pool_sup.erl worker_pool_worker.erl
 APP    rabbit_common
  Compiling some key modules to native code... done in 0m0.37s
  Creating PLT /Users/mopp/repos/rabbitmq-common/.rabbit_common.plt ...
Unknown functions:
  asn1rt_nif:decode_ber_tlv/1
  asn1rt_nif:encode_ber_tlv/1
  ct:pal/1
  dbg:p/2
  dbg:stop/0
  dbg:tpl/2
  dbg:tpl/3
  dbg:trace_client/3
  dbg:trace_port/2
  dbg:tracer/0
  hipe:compile/4
  httpc:request/4
  lager_default_tracer:info/1
Unknown types:
  jsx_verify:config/0
  ssl_cipher:erl_cipher_suite/0
 done in 2m35.36s
done (passed successfully)
  Checking whether the PLT /Users/mopp/repos/rabbitmq-common/.rabbit_common.plt is up-to-date... yes
  Proceeding with analysis...
Unknown functions:
  msacc:start/1
  msacc:stats/0
  msacc:stop/0
  os_mon_sysinfo:get_mem_info/0
Unknown types:
  crypto:block_cipher/0
  crypto:hash_algorithms/0
  rabbit_access_control:permission_atom/0
  rabbit_amqqueue:name/0
  rabbit_binding:key/0
  rabbit_channel:channel_number/0
  rabbit_exchange:name/0
  rabbit_exchange:type/0
  rabbit_framing:amqp_class_id/0
  rabbit_framing:amqp_exception/0
  rabbit_framing:amqp_field_type/0
  rabbit_framing:amqp_method_name/0
  rabbit_framing:amqp_method_record/0
  rabbit_framing:amqp_property_record/0
  rabbit_framing:amqp_table/0
  rabbit_framing:amqp_value/0
  rabbit_framing:protocol/0
  rabbit_guid:guid/0
  rabbit_networking:hostname/0
  rabbit_networking:ip_port/0
  rabbit_router:match_result/0
  rabbit_router:routing_key/0
  rabbit_ssl:certificate/0
  set:set/0
 done in 0m14.19s
done (passed successfully)

It says passed successfully because the dialyzer is configured loosely. Anyway, I also believe your feature work solves them 👍

michaelklishin commented 5 years ago

Erlang 22 is not a released version and it is not currently supported (even though we did test RabbitMQ on it, include).

You say that "Dialyzer is configured loosely" but take a look where do the warnings come from:

RabbitMQ supports two to three major Erlang versions and we do not maintain some of our dependencies. Figuring out a way to dialyze all components together is something we plan on doing.

mopp commented 5 years ago

Erlang 22 is not a released version and it is not currently supported (even though we did test RabbitMQ on it, include).

I retried to dialyze on Erlang/OTP 21.3. The same warnings are obtained.

Then, I found that these types are defined in simplegeo/rabbitmq-server.

I'm very sorry. I found the link is wrong. The correct one is rabbitmq/rabbitmq-server: Open source multi-protocol messaging broker.

I understand that some errors (e.g., crypto:block_cipher/0) come from OTP and dependencies that rabbitmq team does not own. the other warnings like rabbit_XXX come from rabbitmq-common. Will your team fix the other warnings (e.g., rabbit_ssl:certificate/0) ?

Figuring out a way to dialyze all components together is something we plan on doing.

IMIO, A library passes dialyzer without combining others.

michaelklishin commented 5 years ago

We plan on adding Dialyzer to our pipeline reasonably soon, at least for repositories individually.

mopp commented 5 years ago

Ok, I got it. I will wait the issue to be fixed.

Thank you very much for your quick response.