Erlang / ets: reset ets table after receiving a "bad argument"?

I learn how to use ets, but one thing that bothered me is that sometimes * ets:matchthrows away bad argument... And from them all subsequent calls (even calls that previously worked) also throw a bad argument:

> ets: match (Tid, {[$ r | '$ 1']}, 1).
% this match works ...
% Then, at some point, this comes up:
** exception error: bad argument
     in function ets: match / 3
        called as ets: match (24589, {[114 | '$ 1']}, 1)
% And from then on, matches stop working:
> ets: match (Tid, {[$ r | '$ 1']}, 1).
** exception error: bad argument
     in function ets: match / 3
        called as ets: match (24589, {[114 | '$ 1']}, 1)

Is there a way to "reset" the system etsso that I can request it again (i.e. from the shell)?

*: I could not reproduce the problem ... But this happens quite often while I try to do "other things".

+4
source share
2 answers

Although I'm not 100% sure, this thread seems to answer your question. It looks like you are observing this behavior in a shell. If so, the two facts interact in an intricate way:

  • The ets table is deleted as soon as the ownership process dies.
  • The erlang layer dies when it receives an exception and silently restarts.

, , , ets, . , ets:match, , .

+10

, . , self() .

, . .

1> self().
<0.32.0>    % shell Pid

2> spawn(fun() -> ets:new(my_table, [named_table, public]), receive X -> ok end end).
<0.35.0>    % the spawned process Pid

3> ets:insert(my_table, {a, b}).
true

, .

4> 1/0.
** exception error: bad argument in an arithmetic expression
     in operator  '/'/2
        called as 1 / 0
5> self().
<0.38.0>   % shell reborn, with a different Pid

6> ets:insert(my_table, {c, d}).
true
7> ets:tab2list(my_table).
[{c,d},{a,b}]    % table did survive the shell restart

, - :

8> pid(0,35,0) ! bye_bye.
bye_bye
9> ets:info(my_table).   
undefined
+2