aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src
diff options
context:
space:
mode:
authorHans Bolinder <[email protected]>2016-01-25 10:35:20 +0100
committerHans Bolinder <[email protected]>2016-01-26 08:54:27 +0100
commit332d61900b466c3bb9f3892d272043e2ad3ffb90 (patch)
tree791a680b9cf78709cdfe407b25180f6db63b11d0 /lib/stdlib/src
parentfe2d78e98e01fb8a596bd6816e2f154a2d5cfdd0 (diff)
downloadotp-332d61900b466c3bb9f3892d272043e2ad3ffb90.tar.gz
otp-332d61900b466c3bb9f3892d272043e2ad3ffb90.tar.bz2
otp-332d61900b466c3bb9f3892d272043e2ad3ffb90.zip
Fix a race bug affecting dets_SUITE:open_file/2
The Dets server pretends the file is open before internal_open() has been called, which means that unless the internal_open message is applied first, other processes can find the pid by calling dets_server:get_pid() and do things before Head has been initialized properly.
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r--lib/stdlib/src/dets.erl10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/stdlib/src/dets.erl b/lib/stdlib/src/dets.erl
index 7036316242..6887bda67c 100644
--- a/lib/stdlib/src/dets.erl
+++ b/lib/stdlib/src/dets.erl
@@ -1291,7 +1291,15 @@ init(Parent, Server) ->
open_file_loop(#head{parent = Parent, server = Server}).
open_file_loop(Head) ->
- open_file_loop(Head, 0).
+ %% The Dets server pretends the file is open before
+ %% internal_open() has been called, which means that unless the
+ %% internal_open message is applied first, other processes can
+ %% find the pid by calling dets_server:get_pid() and do things
+ %% before Head has been initialized properly.
+ receive
+ ?DETS_CALL(From, {internal_open, _Ref, _Args}=Op) ->
+ do_apply_op(Op, From, Head, 0)
+ end.
open_file_loop(Head, N) when element(1, Head#head.update_mode) =:= error ->
open_file_loop2(Head, N);