[ejabberd] race condition in session creation?

Stephan Maihöfer sma at turtle-entertainment.de
Wed Sep 21 19:47:39 MSD 2011


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).


More information about the ejabberd mailing list