Skip to content

Do not fail on bind/unbind operations if the binding records are inconsistent. #1884

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

Merged
merged 2 commits into from
Feb 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions src/rabbit_binding.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@

-type bind_ok_or_error() :: 'ok' | bind_errors() |
rabbit_types:error(
'binding_not_found' |
{'binding_invalid', string(), [any()]}).
-type bind_res() :: bind_ok_or_error() | rabbit_misc:thunk(bind_ok_or_error()).
-type inner_fun() ::
Expand Down Expand Up @@ -178,19 +177,15 @@ add(Src, Dst, B, ActingUser) ->
lock_resource(Src),
lock_resource(Dst),
[SrcDurable, DstDurable] = [durable(E) || E <- [Src, Dst]],
case (SrcDurable andalso DstDurable andalso
mnesia:read({rabbit_durable_route, B}) =/= []) of
false -> ok = sync_route(#route{binding = B}, SrcDurable, DstDurable,
fun mnesia:write/3),
x_callback(transaction, Src, add_binding, B),
Serial = rabbit_exchange:serial(Src),
fun () ->
x_callback(Serial, Src, add_binding, B),
ok = rabbit_event:notify(
binding_created,
info(B) ++ [{user_who_performed_action, ActingUser}])
end;
true -> rabbit_misc:const({error, binding_not_found})
ok = sync_route(#route{binding = B}, SrcDurable, DstDurable,
fun mnesia:write/3),
x_callback(transaction, Src, add_binding, B),
Serial = rabbit_exchange:serial(Src),
fun () ->
x_callback(Serial, Src, add_binding, B),
ok = rabbit_event:notify(
binding_created,
info(B) ++ [{user_who_performed_action, ActingUser}])
end.

-spec remove(rabbit_types:binding()) -> bind_res().
Expand All @@ -208,7 +203,10 @@ remove(Binding, InnerFun, ActingUser) ->
case mnesia:read(rabbit_route, B, write) of
[] -> case mnesia:read(rabbit_durable_route, B, write) of
[] -> rabbit_misc:const(ok);
_ -> rabbit_misc:const({error, binding_not_found})
%% We still delete the binding and run
%% all post-delete functions if there is only
%% a durable route in the database
_ -> remove(Src, Dst, B, ActingUser)
end;
_ -> case InnerFun(Src, Dst) of
ok -> remove(Src, Dst, B, ActingUser);
Expand Down