[ejabberd] race condition in session creation?

Stephan Maihöfer sma at turtle-entertainment.de
Thu Sep 22 00:20:41 MSD 2011


that should have been a mnesia:dirty_write...sorry.


-----Ursprüngliche Nachricht-----
Von: ejabberd-bounces at jabber.ru im Auftrag von Stephan Maihöfer
Gesendet: Mi 21.09.2011 17:47
An: ejabberd at jabber.ru
Betreff: [ejabberd] race condition in session creation?

i just had a quite long walk through the ejabberd sourcecode
because we had problems creating sessions using http-prebinding
and found that the attached patch this fixes the problem.

it seems that the mnesia:write in handle_session_start/8 in ejabberd_http_bind.erl
"sometimes" takes to long for the mnesia:dirty_read in http_put (that
get's called a bit later during session creation) to then find the
session in the database.

i changed the transactional write to do a dirty_write which fixed
our problems. doing the read in a transaction seemed to dangerous
reading up on locks an the mnesia documentation.

i guess this means that there is a chance that sessions get created
doubly now? how real is that and is there a proper way to prevent
that and not run into a race condition?

stephan maihöfer

Index: ejabberd_http_bind.erl
--- ejabberd_http_bind.erl      (revision 646)
+++ ejabberd_http_bind.erl      (working copy)
@@ -283,9 +283,7 @@
     XmppVersion = xml:get_attr_s("xmpp:version", Attrs),
     ?DEBUG("Create session: ~p", [Sid]),
-    mnesia:transaction(
-      fun() ->
-             mnesia:write(
+    mnesia:write(
                #http_bind{id = Sid,
                           pid = Pid,
                           to = {XmppDomain,
@@ -294,8 +292,8 @@
                           wait = Wait,
                           process_delay = Pdelay,
                           version = Version
-                         })
-      end),
+                         }
+    ),
     handle_http_put(Sid, Rid, Attrs, Payload, PayloadSize, true, IP).

ejabberd mailing list
ejabberd at jabber.ru

-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 3659 bytes
Desc: not available
URL: <http://lists.jabber.ru/pipermail/ejabberd/attachments/20110921/cfe5f99f/attachment.bin>

More information about the ejabberd mailing list