Permalink
Browse files

Fix capability system race condition

Prevent the node from crashing when the capability system attempts to
negotiate capabilities before the node has registered any capabilities.
  • Loading branch information...
1 parent 5404bf8 commit 8b6e04dbb3e4e6044e427ea138e10063dfbad374 @jtuple jtuple committed Jul 21, 2012
Showing with 11 additions and 7 deletions.
  1. +11 −7 src/riak_core_capability.erl
@@ -395,13 +395,17 @@ add_supported_to_ring(Node, Supported, Ring) ->
%% in the cluster.
negotiate_capabilities(Node, Override, State=#state{registered=Registered,
supported=Capabilities}) ->
- MyCaps = orddict:fetch(Node, Capabilities),
- N1 = reformat_capabilities(Registered, Capabilities),
- N2 = intersect_capabilities(N1),
- N3 = order_by_preference(MyCaps, N2),
- N4 = override_capabilities(N3, Override),
- N5 = [{Cap, hd(Common)} || {Cap, Common} <- N4],
- State#state{negotiated=N5}.
+ case orddict:find(Node, Capabilities) of
+ error ->
+ State;
+ {ok, MyCaps} ->
+ N1 = reformat_capabilities(Registered, Capabilities),
+ N2 = intersect_capabilities(N1),
+ N3 = order_by_preference(MyCaps, N2),
+ N4 = override_capabilities(N3, Override),
+ N5 = [{Cap, hd(Common)} || {Cap, Common} <- N4],
+ State#state{negotiated=N5}
+ end.
renegotiate_capabilities(State=#state{supported=[]}) ->
State;

0 comments on commit 8b6e04d

Please sign in to comment.