diff options
author | Hans Bolinder <[email protected]> | 2014-10-23 09:00:48 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2014-10-23 09:00:48 +0200 |
commit | ff3fae223431a9cb0d2a2852a07f9447960c92ed (patch) | |
tree | 3faeb5fb24999a54b190bac9b844a89e93d9ac54 /lib/stdlib/src/dets_server.erl | |
parent | cd5628a99bff391377042f93e8d85da818235217 (diff) | |
parent | 89c5bc9a243d7f0ba8e43b52b9addadccdb7d1ca (diff) | |
download | otp-ff3fae223431a9cb0d2a2852a07f9447960c92ed.tar.gz otp-ff3fae223431a9cb0d2a2852a07f9447960c92ed.tar.bz2 otp-ff3fae223431a9cb0d2a2852a07f9447960c92ed.zip |
Merge branch 'hb/stdlib/fix_dets_test' into maint
* hb/stdlib/fix_dets_test:
Fix rare race condition in Dets
Diffstat (limited to 'lib/stdlib/src/dets_server.erl')
-rw-r--r-- | lib/stdlib/src/dets_server.erl | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/stdlib/src/dets_server.erl b/lib/stdlib/src/dets_server.erl index 268c201047..3164d40f35 100644 --- a/lib/stdlib/src/dets_server.erl +++ b/lib/stdlib/src/dets_server.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2001-2013. All Rights Reserved. +%% Copyright Ericsson AB 2001-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -171,9 +171,15 @@ handle_info({pending_reply, {Ref, Result0}}, State) -> link(Pid), do_link(Store, FromPid), true = ets:insert(Store, {FromPid, Tab}), - true = ets:insert(?REGISTRY, {Tab, 1, Pid}), - true = ets:insert(?OWNERS, {Pid, Tab}), + %% do_internal_open() has already done the following: + %% true = ets:insert(?REGISTRY, {Tab, 1, Pid}), + %% true = ets:insert(?OWNERS, {Pid, Tab}), {ok, Tab}; + {Reply, internal_open} -> + %% Clean up what do_internal_open() did: + true = ets:delete(?REGISTRY, Tab), + true = ets:delete(?OWNERS, Pid), + Reply; {Reply, _} -> % ok or Error Reply end, @@ -309,6 +315,12 @@ do_internal_open(State, From, Args) -> [T, _, _] -> T; [_, _] -> Ref end, + %% Pretend the table is open. If someone else tries to + %% open the file it will always become a pending + %% 'add_user' request. If someone tries to use the table + %% there will be a delay, but that is OK. + true = ets:insert(?REGISTRY, {Tab, 1, Pid}), + true = ets:insert(?OWNERS, {Pid, Tab}), pending_call(Tab, Pid, Ref, From, Args, internal_open, State); Error -> {Error, State} |