pma/amqp

Application.Connection has a missing case clause on line 113

begedin opened this issue · 1 comments

https://github.com/pma/amqp/blob/main/lib/amqp/application/channel.ex#L113

I'm not really sure how this should be resolved, but on our production app, we had a cascade failure where AMQP processes were often restarting and, among the several things we had issues with, one of them was that the line

https://github.com/pma/amqp/blob/main/lib/amqp/application/channel.ex#L113

does not implement all the result clasuse. Apparently, one of the results could be

18:45:09.147 [error] Supervisor 'Elixir.AMQP.Application' had child 
'Elixir.AMQP.Application.Channel::producers'  started with 
'Elixir.AMQP.Application.Channel':start_link([{connection,mq_gate},{proc_name,producers}]) at <0.19215.77> 
exit with reason no case clause matching closing in 'Elixir.AMQP.Application.Channel':handle_info/2 line 113 
in context child_terminated    
@impl true
  def handle_info(:open, state) do
    case AMQP.Application.Connection.get_connection(state[:connection]) do
      {:ok, conn} ->
        case Channel.open(conn) do
          {:ok, chan} ->
            # ...
          {:error, error} ->
            # ...   

So it seems Channel.open(conn) can result in :closing, though is not apparent to me from the underlying erlang library. I would love to push a patch but I'm not sure what the appropriate way to handle it would be. Any pointers are welcome. I'm thinking same approach as with {:error, error} would work?

EDIT: Digging deep into the erlang library, it looks like amqp_gen_connection.erl

open_channel(Pid, ProposedNumber, Consumer) ->
  case gen_server:call(Pid,
                       {command, {open_channel, ProposedNumber, Consumer}},
                       amqp_util:call_timeout()) of
      {ok, ChannelPid} -> ok = amqp_channel:open(ChannelPid),
                          {ok, ChannelPid};
      Error            -> Error
  end.

returns {:ok, pid} | any

While deps/amqp_client/src/amqp_connection.erl

defines the return for open_channel/2 as Result = {ok, ChannelPid} | {error, Error}

So it seems there's a discrepancy there.

Pushed a "proposal" PR. Open to any advice/criticism.