rabbitmq / ra

A Raft implementation for Erlang and Elixir that strives to be efficient and make it easier to use multiple Raft clusters in a single system.
Other
813 stars 96 forks source link

Fix a bug that `ra:restart_server/2` could raise an exception #359

Closed sile closed 1 year ago

sile commented 1 year ago

Proposed Changes

This PR fixes a bug that ra:restart_server/2 could raise a case_clause exception as the function doesn't handle {badrpc, _} (a possible return value of ra_server_sup_sup:restart_server()).

I ran into this bug when I tested how ra works if disk failure happens (as an example of the exception, see the stacktrace below).

{{case_clause,
  {badrpc,
   {'EXIT',
    {badarg,
     [{dets,lookup,
       [ra_directory_reverse, foo],
       [{file,"dets.erl"},{line,1269}]},
      {ra_directory,uid_of,2,
       [{file,
         "/foo/_build/default/lib/ra/src/ra_directory.erl"},
        {line,166}]},
      {ra_server_sup_sup,recover_config,2,
       [{file,
         "/foo/_build/default/lib/ra/src/ra_server_sup_sup.erl"},
        {line,203}]},
      {ra_server_sup_sup,restart_server_rpc,3,
       [{file,
         "/foo/_build/default/lib/ra/src/ra_server_sup_sup.erl"},
        {line,86}]}]}}}},
 [{ra,restart_server,2,
   [{file,
     "/foo/_build/default/lib/ra/src/ra.erl"},
    {line,174}]}, ...

I could not make a reproducing code or a test case that cover this case as it's too rare and hard.

Types of Changes

What types of changes does your code introduce to this project? Put an x in the boxes that apply

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask on the mailing list. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

Further Comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc.

kjnilsson commented 1 year ago

Thanks!