Skip to content

Instantly share code, notes, and snippets.

@marcparadise
Last active August 29, 2015 14:26
Show Gist options
  • Save marcparadise/e65234d095ef4e1f4799 to your computer and use it in GitHub Desktop.
Save marcparadise/e65234d095ef4e1f4799 to your computer and use it in GitHub Desktop.
Reproduces a deadlock in oc_bifrost's update_acl stored proc.
% Run this in an oc_bifrost console to reproduce the deadlocks.
% Don't run this in a production DB as it doesn't clean up after itself.
MakeID = fun() ->
Raw = crypto:rand_bytes(16),
<<Guid:128>> = Raw,
iolist_to_binary(io_lib:format("~32.16.0b", [Guid])) end.
ActorIds = [ MakeID() || X <- lists:seq(1,5) ].
[ bifrost_db:create(actor, Id, undefined) || Id <- ActorIds ].
GroupIds = [ MakeID() || X <- lists:seq(1,5) ].
[ bifrost_db:create(group, Id, undefined) || Id <- GroupIds].
ObjectId = MakeID().
bifrost_db:create(object, ObjectId, undefined).
LockUp = fun(Num) -> R = bifrost_db:update_acl(object, ObjectId, "create", ActorIds, GroupIds), io:fwrite("~p: ~p ~n", [Num, R]) end.
[spawn(fun() -> LockUp(X)) end || X <- lists:seq(1,100)].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment