[ejabberd] How Ejabberd hooks work

Uday Sawant uday at sweetcouch.com
Sat Feb 21 14:38:50 MSK 2015


Hi All,

I would like to get some details on working of ejabberd hooks. Do they work
Synchronously or Async.

I noticed this strange behaviour where the messages sent to offline user
did not get stored to db till the complete execution of listener chain of
offline_message_hook. The details are as follows

Setup:
1. Ejabberd installation 14.07 compiled from source with erlang 16B-03
2. Ejabberd runs in cluster mode with 2 nodes in same network
3. mod_offline enabled which runs at #50
4. mod_offline_post which listens on offline_message_hook at #99. This
module, for each offline message make a synchronous http call to remote
server which triggers notification on respective device.

Test scenario:
1. Two users A and B. Both subscribed to each other.
2. User A is offline and will receive notification for any offline msg
received
3. User B send 10 continuous messages to user A (say 1 - 10)

Observations:
1. Client of A wakes up after receiving 10 notifications and receives all
10 messages
2. Client A wakes in between say after notification #3
    a. message 1-3 gets delivered with delayed notification
    b. message #4 is not received.
    c. message 5-10 get delivered normally
3. Client A goes offline and then come online after few seconds
    a. message #4 gets delivered now.

Similarly in other observation
1. Client try to fetch offline messages as soon as it receives the
notification
    - no message found in offline storage
2. Client try to fetch message after delay of 3-5 sec from notification
    - message retrieved successfully


If I turn off the *mod_offline_post* module everything works fine. OR even
if I change the *httpc:request* call in *mod_offline_post* to *async* call
everything works fine.

My question is why *mod_offline* waits for completion of other modules on
the chain. It should push the message to db as soon as it receives it. When
we say "hooks" the listeners are expected to work asynchronously in
separate processes. but it doesn't  appears to be so. Am I missing some
basics?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.jabber.ru/pipermail/ejabberd/attachments/20150221/8a5e2945/attachment.html>


More information about the ejabberd mailing list