aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMickael Remond <mremond@process-one.net>2016-07-26 11:58:14 +0200
committerMickael Remond <mremond@process-one.net>2016-07-26 11:58:14 +0200
commit9ff7257287b6a7339cd3f5503f46e8b6b70308c7 (patch)
tree26184d3097ac7239b9fbb23f0c56d1e655029aa0
parentFix list appending bug (diff)
Make jlib ETS table more resilient
-rw-r--r--src/jid.erl13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/jid.erl b/src/jid.erl
index 0c3ac77c0..46830d031 100644
--- a/src/jid.erl
+++ b/src/jid.erl
@@ -50,11 +50,22 @@
-spec start() -> ok.
start() ->
+ Owner = spawn(fun() -> ets_keepalive() end),
SplitPattern = binary:compile_pattern([<<"@">>, <<"/">>]),
- catch ets:new(jlib, [named_table, protected, set, {keypos, 1}]),
+ %% Table is public to allow ETS insert to fix / update the table even if table already exist
+ %% with another owner.
+ catch ets:new(jlib, [named_table, public, set, {keypos, 1}, {heir, Owner, undefined}]),
ets:insert(jlib, {string_to_jid_pattern, SplitPattern}),
ok.
+%% Process used to keep jlib ETS table alive in case the original owner dies.
+%% The table need to be public, otherwise subsequent inserts would fail.
+ets_keepalive() ->
+ receive
+ _ ->
+ ets_keepalive()
+ end.
+
-spec make(binary(), binary(), binary()) -> jid() | error.
make(User, Server, Resource) ->