diff options
author | John Högberg <[email protected]> | 2019-05-14 13:39:00 +0200 |
---|---|---|
committer | John Högberg <[email protected]> | 2019-05-14 13:39:00 +0200 |
commit | 416d7690d325f10c20fd7080ef324e76acae11c1 (patch) | |
tree | 63c7dbd024da6e892eb58ec5aaa53b20da71a252 /lib/tools/src/cover.erl | |
parent | 53b76a3b2c1ce19f2eb85d1b788e3c09958fd18a (diff) | |
parent | 656420b64c9207ef5fc25c107b5f4a457b6359bd (diff) | |
download | otp-416d7690d325f10c20fd7080ef324e76acae11c1.tar.gz otp-416d7690d325f10c20fd7080ef324e76acae11c1.tar.bz2 otp-416d7690d325f10c20fd7080ef324e76acae11c1.zip |
Merge branch 'john/tools/fix-cover-register-race/ERL-943/OTP-15813' into maint
* john/tools/fix-cover-register-race/ERL-943/OTP-15813:
cover: Fix register/2 race on startup
Diffstat (limited to 'lib/tools/src/cover.erl')
-rw-r--r-- | lib/tools/src/cover.erl | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/lib/tools/src/cover.erl b/lib/tools/src/cover.erl index 8fe866cb69..2b3af417b6 100644 --- a/lib/tools/src/cover.erl +++ b/lib/tools/src/cover.erl @@ -196,6 +196,8 @@ start() -> receive {?SERVER,started} -> {ok,Pid}; + {?SERVER,{error,Error}} -> + {error,Error}; {'DOWN', Ref, _Type, _Object, Info} -> {error,Info} end, @@ -645,19 +647,31 @@ remote_reply(MainNode,Reply) -> %%%---------------------------------------------------------------------- init_main(Starter) -> - register(?SERVER,self()), - ?COVER_MAPPING_TABLE = ets:new(?COVER_MAPPING_TABLE, - [ordered_set, public, named_table]), - ?COVER_CLAUSE_TABLE = ets:new(?COVER_CLAUSE_TABLE, [set, public, - named_table]), - ?BINARY_TABLE = ets:new(?BINARY_TABLE, [set, public, named_table]), - ?COLLECTION_TABLE = ets:new(?COLLECTION_TABLE, [set, public, - named_table]), - ?COLLECTION_CLAUSE_TABLE = ets:new(?COLLECTION_CLAUSE_TABLE, [set, public, - named_table]), - ok = net_kernel:monitor_nodes(true), - Starter ! {?SERVER,started}, - main_process_loop(#main_state{}). + try register(?SERVER,self()) of + true -> + ?COVER_MAPPING_TABLE = ets:new(?COVER_MAPPING_TABLE, + [ordered_set, public, named_table]), + ?COVER_CLAUSE_TABLE = ets:new(?COVER_CLAUSE_TABLE, [set, public, + named_table]), + ?BINARY_TABLE = ets:new(?BINARY_TABLE, [set, public, named_table]), + ?COLLECTION_TABLE = ets:new(?COLLECTION_TABLE, [set, public, + named_table]), + ?COLLECTION_CLAUSE_TABLE = ets:new(?COLLECTION_CLAUSE_TABLE, + [set, public, named_table]), + ok = net_kernel:monitor_nodes(true), + Starter ! {?SERVER,started}, + main_process_loop(#main_state{}) + catch + error:badarg -> + %% The server's already registered; either report that it's already + %% started or try again if it died before we could find its pid. + case whereis(?SERVER) of + undefined -> + init_main(Starter); + Pid -> + Starter ! {?SERVER, {error, {already_started, Pid}}} + end + end. main_process_loop(State) -> receive |