Colm Dougan | 19 Aug 15:30

Possible bug after ets:insert exception

Hi,

I'm running 12B-3.  Below is a console session.  Everything worked as
expected until "4>" where I unintentionally provided an atom in my
insert and I get a bad arg.  Again that was expected.  What I didn't
expect, however, was that from then on the ets table seemed to be in a
bad state and couldn't be queried.  I realise this is an edge case.
Is this a bug?

Colm

Eshell V5.6.3  (abort with ^G)
1> ets:new(testtable,[set,named_table,private]).
testtable
2> ets:insert(testtable, [{foo, 10}]).
true
3> ets:tab2list(testtable).
[{foo,10}]
4> ets:insert(testtable, bar).
** exception error: bad argument
     in function  ets:insert/2
        called as ets:insert(testtable,bar)
5> ets:tab2list(testtable).
** exception error: bad argument
     in function  ets:match_object/2
        called as ets:match_object(testtable,'_')
     in call from ets:tab2list/1
Robert Raschke | 19 Aug 15:57

Re: Possible bug after ets:insert exception

On Tue, Aug 19, 2008 at 2:33 PM, Colm Dougan <colm.dougan <at> gmail.com> wrote:
> Eshell V5.6.3  (abort with ^G)
> 1> ets:new(testtable,[set,named_table,private]).
> testtable
> 2> ets:insert(testtable, [{foo, 10}]).
> true
> 3> ets:tab2list(testtable).
> [{foo,10}]
> 4> ets:insert(testtable, bar).
> ** exception error: bad argument
>     in function  ets:insert/2
>        called as ets:insert(testtable,bar)
> 5> ets:tab2list(testtable).
> ** exception error: bad argument
>     in function  ets:match_object/2
>        called as ets:match_object(testtable,'_')
>     in call from ets:tab2list/1

I think this is probably due to the shell having crashed in step 4.
The restarted shell (a new process) no longer knows about testtable. I
have been confused by crashed/restarted shells in the past. But I'm
not 100% sure that is what you're seeing. There's been threads about
this in the past.

Robby
Gleb Peregud | 19 Aug 16:09
Gravatar

Re: Possible bug after ets:insert exception

On Tue, Aug 19, 2008 at 3:33 PM, Colm Dougan <colm.dougan <at> gmail.com> wrote:
> Hi,
>
> I'm running 12B-3.  Below is a console session.  Everything worked as
> expected until "4>" where I unintentionally provided an atom in my
> insert and I get a bad arg.  Again that was expected.  What I didn't
> expect, however, was that from then on the ets table seemed to be in a
> bad state and couldn't be queried.  I realise this is an edge case.
> Is this a bug?
>
> Colm
>
> Eshell V5.6.3  (abort with ^G)
> 1> ets:new(testtable,[set,named_table,private]).
> testtable
> 2> ets:insert(testtable, [{foo, 10}]).
> true
> 3> ets:tab2list(testtable).
> [{foo,10}]
> 4> ets:insert(testtable, bar).
> ** exception error: bad argument
>     in function  ets:insert/2
>        called as ets:insert(testtable,bar)
> 5> ets:tab2list(testtable).
> ** exception error: bad argument
>     in function  ets:match_object/2
>        called as ets:match_object(testtable,'_')
>     in call from ets:tab2list/1
> _______________________________________________
> erlang-questions mailing list
(Continue reading)

Paul Fisher | 19 Aug 15:41
Favicon

Re: Possible bug after ets:insert exception

Colm Dougan wrote:
> I'm running 12B-3.  Below is a console session.  Everything worked as
> expected until "4>" where I unintentionally provided an atom in my
> insert and I get a bad arg.  Again that was expected.  What I didn't
> expect, however, was that from then on the ets table seemed to be in a
> bad state and couldn't be queried.  I realise this is an edge case.
> Is this a bug?

No, not a bug.  What is happening is the shell process which owned the 
ets table died when the exception was generated and therefore the ets 
table was cleaned up.  This is confusing since the shell appears to keep 
going after printing out the exception messages, but in fact it is 
another process.

--
paul
Andras Georgy Bekes | 19 Aug 16:24

Re: Possible bug after ets:insert exception

> Is this a bug?
>
> 4> ets:insert(testtable, bar).
> ** exception error: bad argument
>      in function  ets:insert/2
>         called as ets:insert(testtable,bar)
> 5> ets:tab2list(testtable).
> ** exception error: bad argument
>      in function  ets:match_object/2
>         called as ets:match_object(testtable,'_')
>      in call from ets:tab2list/1

Each ETS table has an owner process. The owner is the process that 
created the table. The table is automatically deleted when the owner 
quits.

The owner of your table was the shell process which crashed with badarg. 
The shell automatically created a new shell process for you, but the 
table was gone with the previous shell process.

	Georgy

Re: Possible bug after ets:insert exception


Hi Colm

It is not a bug. You crashed the shell(Owner of the table) at 4>

See Below:

6> ets:tab2list(testtable).
[{foo,10}]
7> 
7> catch ets:insert(testtable, bar).
{'EXIT',{badarg,[{ets,insert,[testtable,bar]},
                 {erl_eval,do_apply,5},
                 {erl_eval,expr,5},
                 {shell,exprs,6},
                 {shell,eval_loop,3}]}}
8> 
8> ets:tab2list(testtable).         
[{foo,10}]
9> self().
<0.34.0>
10> ets:insert(testtable, bar).      

=ERROR REPORT==== 19-Aug-2008::16:13:15 ===
Error in process <0.34.0> with exit value:
{badarg,[{ets,insert,[testtable,bar]}
,{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]}

** exited: {badarg,[{ets,insert,[testtable,bar]},
                    {erl_eval,do_apply,5},
(Continue reading)

Re: Possible bug after ets:insert exception


Hi

It's not a bug. The shell crashed when you tried to insert the atom (due
to the uncaught exception). This is because you started the ETS table
from the shell, so the ETS table is linked to that particular shell
process.

Try:
1> self().
2> ets:new(testtable,[set,named_table,private]).
3> ets:insert(testtable, bar).
4> self().

You will notice that the shell's pid's are different at (1) and (4).

If you put a "catch" in front of the ets:insert at (3) it will catch the
exception and the shell will not crash.

Regards,
Trevor

-----Original Message-----
From: erlang-questions-bounces <at> erlang.org
[mailto:erlang-questions-bounces <at> erlang.org] On Behalf Of Colm Dougan
Sent: Tuesday, 19 August 2008 03:34 PM
To: erlang-questions <at> erlang.org
Subject: [erlang-questions] Possible bug after ets:insert exception

Hi,
(Continue reading)


Gmane