processone / ejabberd

Robust, Ubiquitous and Massively Scalable Messaging Platform (XMPP, MQTT, SIP Server)
https://www.process-one.net/en/ejabberd/
Other
6.08k stars 1.51k forks source link

ets_cache behaviour #2310

Open dmitri-anghiloglu opened 6 years ago

dmitri-anghiloglu commented 6 years ago

What version of ejabberd are you using? 17.11

What operating system (version) are you using? ubuntu 16.10

How did you install ejabberd (source, package, distribution)? source

What did not work as expected? Are there error messages in the log? What was the unexpected behavior? What was the expected result?

Use case ejabberd_auth (auth_cache) User tries to authenticate for the first time and at that moment connection to db fails(returns and error). Current implementation saves the error in the cache. User will not be able to authenticate until the cache expiration or password update.

The same behaviour in mod_vcard, mod_roster, mod_privacy etc.

I resolved it for myself only in several important modules ex. ejabberd_auth

db_get_password(User, Server, Mod) ->
  ...
       Password = ets_cache:lookup(
         ?AUTH_CACHE, {User, Server},
         fun() -> Mod:get_password(User, Server) end),
           if Password =:= error ->
                   ets_cache:delete(?AUTH_CACHE, {User, Server});
                   true -> ok
               end,
               Password;
  ...
   end.
zinid commented 6 years ago

That's a tricky question, we still didn't decide yet whether we need to cache DB failures or not. There are definitely cases where it's desired, e.g. when DB is overloaded. We probably need to introduce cache_errors option or something.