[ejabberd] Concurrency issue inside custom Module

Evgeny Khramtsov xramtsov at gmail.com
Wed Aug 9 14:55:09 MSK 2017


Wed, 9 Aug 2017 16:21:19 +0530 (IST)
Abhishek Ranjan <abhishek at blacklightsw.com> wrote:

> I have a custom module running in ejabberd with the following
> function 'myMessage' that is triggered whenever a chat message is
> sent by the client.
> 
> I call some other module's functions from this function myMessage as
> follows: 
> 
> myMessage({#message = Msg, C2SState})->
> 
> 
>     some_other_module:some_func(Args),
>     State=mnesia_module:read(key),
>    
>     {Msg, C2SState};
> myMessage(Acc) ->
>     Acc.

It's hard to say anything from such abstract code, even though you
somehow described it. I can only say that if there is no race between
some_other_module:some_func/1 and mnesia_module:read/1, then there
shouldn't be any races at all, because the hook (which myMessage is
associated with) is called inside a single process *synchronously*.

Regarding Mnesia decision: it's indeed pointless to use Mnesia here if
you just need to keep values on the c2s state (without storing them on
disc).


More information about the ejabberd mailing list