[erlang-bugs] mnesia subscription

Tobias Schlager Tobias.Schlager@REDACTED
Tue Sep 23 14:49:42 CEST 2014


Hi,

I just found out the hard way, that mnesia:subscribe/1 might lie to you, when you trap exits and are linked to other processes. Although running, Mnesia sometimes returns '{error,{node_not_running,nonode@REDACTED}}' when trying to subscribe. Even worse subsequent calls to subscribe from the same process tell you that the subscription actually took place (returning '{error,{already_exists,Category}}'). This is due to a receive statement located in mnesia_subscr:call/1 that tries to unify the functions return value. Unfortunately, it doesn't match for a specific process id, so every 'EXIT' message in the callers message queue will be consumed and trigger the false value.

For a minimal test case fire up an erlang shell and do the following:
1> application:start(mnesia).
ok
2> process_flag(trap_exit, true).
false
3> spawn_link(fun() -> ok end).  
<0.52.0>
4> mnesia:subscribe(system).     
{error,{node_not_running,nonode@REDACTED}}
5> mnesia:subscribe(system).
{error,{already_exists,system}}
6> mnesia:unsubscribe(system).
{ok,nonode@REDACTED}
7> mnesia:subscribe(system).  
{ok,nonode@REDACTED}

Regards
Tobias



More information about the erlang-bugs mailing list