Skip to content

Commit

Permalink
Tolerate race condition when starting management db cache process
Browse files Browse the repository at this point in the history
This prevents the below harmless crash when multiple parallel API
requests arrive soon after starting the node.

```
exception error: no match of right hand side value
                 {error,{already_started,<0.1593.0>}}
  in function  rabbit_mgmt_db_cache:fetch/4 (rabbit_mgmt_db_cache.erl, line 68)
  in call from rabbit_mgmt_db:submit_cached/4 (rabbit_mgmt_db.erl, line 756)
  in call from rabbit_mgmt_util:augment/2 (rabbit_mgmt_util.erl, line 412)
  in call from rabbit_mgmt_util:run_augmentation/2 (rabbit_mgmt_util.erl, line 389)
  in call from rabbit_mgmt_util:augment_resources0/6 (rabbit_mgmt_util.erl, line 378)
  in call from rabbit_mgmt_util:with_valid_pagination/3 (rabbit_mgmt_util.erl, line 302)
  in call from rabbit_mgmt_wm_queues:to_json/2 (rabbit_mgmt_wm_queues.erl, line 44)
  in call from cowboy_rest:call/3 (src/cowboy_rest.erl, line 1583)
```
  • Loading branch information
gomoripeti committed Dec 19, 2023
1 parent 9d411e4 commit f4a9edf
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions deps/rabbitmq_management/src/rabbit_mgmt_db_cache.erl
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,14 @@ fetch(Key, FetchFun, FunArgs, Timeout) ->
ProcName = process_name(Key),
Pid = case whereis(ProcName) of
undefined ->
{ok, P} = supervisor:start_child(rabbit_mgmt_db_cache_sup,
?CHILD(Key)),
P;
case supervisor:start_child(rabbit_mgmt_db_cache_sup,
?CHILD(Key)) of
{ok, P} ->
P;
{error, {already_started, P}} ->
%% A parallel request started the cache meanwhile
P
end;
P -> P
end,
gen_server:call(Pid, {fetch, FetchFun, FunArgs}, Timeout).
Expand Down

0 comments on commit f4a9edf

Please sign in to comment.