Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for port to be configured as a string #163

Merged
merged 4 commits into from
Feb 25, 2020
Merged

Conversation

akoutmos
Copy link
Contributor

This is a quality of life change for configuring connections to RabbitMQ. If the port is provided as a string (which is often the time if the port is configured via an environment variable), a cryptic Erlang authentication error if returned back and it makes it difficult to root cause that the problem was merely a type issue (string vs integer). Attaching the error below when this occurs.

The proposed change is something that is also done in Phoenix for similar reasons: https://github.com/phoenixframework/phoenix/blob/b53813bf3e612077c887f4241a3ff82b41ae9a3f/lib/phoenix/endpoint/cowboy2_adapter.ex#L124-L125

I have also added some README changes to make contributing to amqp a bit easier :).

=ERROR REPORT==== 31-Jan-2020::09:34:08.524654 ===
** Generic server <0.241.0> terminating
** Last message in was connect
** When Server state == {<0.240.0>,
                         {amqp_params_network,<<"guest">>,
                             <<"V3ihvPxvBUBPNWzQ37AA6/iZvMYi8yQd25lHVFO+ru5o64ZrBSJV0jFkyL/KsuEw">>,
                             <<"/">>,"localhost",<<"5672">>,0,0,10,50000,none,
                             [fun amqp_auth_mechanisms:plain/3,
                              fun amqp_auth_mechanisms:amqplain/3],
                             [],[]}}
** Reason for termination ==
** {function_clause,
       [{amqp_gen_connection,terminate,
            [{function_clause,
                 [{inet_tcp,getserv,
                      [<<"5672">>],
                      [{file,"inet_tcp.erl"},{line,55}]},
                  {gen_tcp,connect1,4,[{file,"gen_tcp.erl"},{line,176}]},
                  {gen_tcp,connect,4,[{file,"gen_tcp.erl"},{line,163}]},
                  {amqp_network_connection,do_connect,4,
                      [{file,
                           "~/amqp/deps/amqp_client/src/amqp_network_connection.erl"},
                       {line,132}]},
                  {amqp_gen_connection,handle_call,3,
                      [{file,
                           "~/amqp/deps/amqp_client/src/amqp_gen_connection.erl"},
                       {line,174}]},
                  {gen_server,try_handle_call,4,
                      [{file,"gen_server.erl"},{line,661}]},
                  {gen_server,handle_msg,6,
                      [{file,"gen_server.erl"},{line,690}]},
                  {proc_lib,init_p_do_apply,3,
                      [{file,"proc_lib.erl"},{line,249}]}]},
             {<0.240.0>,
              {amqp_params_network,<<"guest">>,
                  <<"V3ihvPxvBUBPNWzQ37AA6/iZvMYi8yQd25lHVFO+ru5o64ZrBSJV0jFkyL/KsuEw">>,
                  <<"/">>,"localhost",<<"5672">>,0,0,10,50000,none,
                  [fun amqp_auth_mechanisms:plain/3,
                   fun amqp_auth_mechanisms:amqplain/3],
                  [],[]}}],
            [{file,
                 "~/amqp/deps/amqp_client/src/amqp_gen_connection.erl"},
             {line,242}]},
        {gen_server,try_terminate,3,[{file,"gen_server.erl"},{line,673}]},
        {gen_server,terminate,10,[{file,"gen_server.erl"},{line,858}]},
        {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}
** Client <0.238.0> stacktrace
** [{gen,do_call,4,[{file,"gen.erl"},{line,167}]},
    {gen_server,call,3,[{file,"gen_server.erl"},{line,219}]},
    {'Elixir.AMQP.Connection',do_open,2,
                              [{file,"lib/amqp/connection.ex"},{line,207}]},
    {'Elixir.ConnectionTest','test open connection with host as binary',1,
                             [{file,"test/connection_test.exs"},{line,12}]},
    {'Elixir.ExUnit.Runner',exec_test,1,
                            [{file,"lib/ex_unit/runner.ex"},{line,355}]},
    {timer,tc,1,[{file,"timer.erl"},{line,166}]},
    {'Elixir.ExUnit.Runner','-spawn_test_monitor/4-fun-1-',4,
                            [{file,"lib/ex_unit/runner.ex"},{line,306}]}]

=CRASH REPORT==== 31-Jan-2020::09:34:08.526813 ===
  crasher:
    initial call: amqp_gen_connection:init/1
    pid: <0.241.0>
    registered_name: []
    exception error: no function clause matching
                     amqp_gen_connection:terminate({function_clause,
                                                    [{inet_tcp,getserv,
                                                      [<<"5672">>],
                                                      [{file,"inet_tcp.erl"},
                                                       {line,55}]},
                                                     {gen_tcp,connect1,4,
                                                      [{file,"gen_tcp.erl"},
                                                       {line,176}]},
                                                     {gen_tcp,connect,4,
                                                      [{file,"gen_tcp.erl"},
                                                       {line,163}]},
                                                     {amqp_network_connection,
                                                      do_connect,4,
                                                      [{file,
                                                        "~/amqp/deps/amqp_client/src/amqp_network_connection.erl"},
                                                       {line,132}]},
                                                     {amqp_gen_connection,
                                                      handle_call,3,
                                                      [{file,
                                                        "~/amqp/deps/amqp_client/src/amqp_gen_connection.erl"},
                                                       {line,174}]},
                                                     {gen_server,
                                                      try_handle_call,4,
                                                      [{file,"gen_server.erl"},
                                                       {line,661}]},
                                                     {gen_server,handle_msg,
                                                      6,
                                                      [{file,"gen_server.erl"},
                                                       {line,690}]},
                                                     {proc_lib,
                                                      init_p_do_apply,3,
                                                      [{file,"proc_lib.erl"},
                                                       {line,249}]}]},
                                                   {<0.240.0>,
                                                    {amqp_params_network,
                                                     <<"guest">>,
                                                     <<"V3ihvPxvBUBPNWzQ37AA6/iZvMYi8yQd25lHVFO+ru5o64ZrBSJV0jFkyL/KsuEw">>,
                                                     <<"/">>,"localhost",
                                                     <<"5672">>,0,0,10,50000,
                                                     none,
                                                     [fun amqp_auth_mechanisms:plain/3,
                                                      fun amqp_auth_mechanisms:amqplain/3],
                                                     [],[]}}) (~amqp/deps/amqp_client/src/amqp_gen_connection.erl, line 242)
      in function  gen_server:try_terminate/3 (gen_server.erl, line 673)
      in call from gen_server:terminate/10 (gen_server.erl, line 858)
    ancestors: [<0.239.0>,amqp_sup,<0.211.0>]
    message_queue_len: 0
    messages: []
    links: [<0.239.0>]
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 6772
    stack_size: 27
    reductions: 21699
  neighbours:

@akoutmos akoutmos changed the title Allow for port to come in as a string Allow for port to be configured as a string Jan 31, 2020
@akoutmos
Copy link
Contributor Author

Any thoughts or input on this PR? Just a friendly bump :)

@ono
Copy link
Collaborator

ono commented Feb 15, 2020

Nice work. I think it makes sense but we might want to be consistent on all integer parameters. It is confusing to do the conversion that only for the port parameter. Can you apply the change to other integer parameters for the function too?

I like to keep the documentation tidy so let's trim as either a string or an integer bit. I still like to encourage users to pass integer here and the expected type is obvious from the default value.

Can you also do README change on a separate PR 🙏? And leave * for a bullet list item? I rather like to change - to * then we can be consistent on the repo. Docker bit is a good tip 👍

@akoutmos
Copy link
Contributor Author

@ono Thanks for the feedback! I went ahead and added the integer normalize functionality to the other integer options like you suggested and also removed the README changes as I can make those in a separate PR.

Let me know if you have any additional comments. Thanks!

@ono
Copy link
Collaborator

ono commented Feb 21, 2020

Sorry for my slow response - I have been bit busy this week. Looking good at glance. I will take a closer look this weekend and merge if there is no issue. Thanks!

@akoutmos
Copy link
Contributor Author

Thanks @ono! Have a nice weekend :)

@ono ono merged commit 18809a0 into pma:master Feb 25, 2020
@ono
Copy link
Collaborator

ono commented Feb 25, 2020

@akoutmos Merged and released 1.4.1. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants